feat: now supports async functions for logging data
- `logger.debug('message', async () => ({ asyncReturn: await asyncFn() }))` is now supported
- NOTE: this may result in logging occurring out of band for these calls if other events fire befor they settle
Update CI labels to direct jobs to correct servers
This commit is contained in:
+18
-5
@@ -1,3 +1,5 @@
|
||||
import { LogLevel as LogLevelEnum, LoggerEnvironment as LoggerEnvironmentEnum } from "./constants";
|
||||
|
||||
/**
|
||||
* Severity threshold for log filtering, ordered from most to least verbose.
|
||||
*
|
||||
@@ -13,7 +15,7 @@
|
||||
* A logger emits events at or above its configured threshold (e.g. `warn`
|
||||
* allows `warn` and `error`).
|
||||
*/
|
||||
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
|
||||
export type LogLevel = `${LogLevelEnum}`;
|
||||
|
||||
/**
|
||||
* Deployment stage used to pick a default log level when none is configured
|
||||
@@ -24,20 +26,23 @@ export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
|
||||
* - `staging` → `warn`
|
||||
* - `production` → `error`
|
||||
*/
|
||||
export type LoggerEnvironment = "development" | "staging" | "production";
|
||||
export type LoggerEnvironment = `${LoggerEnvironmentEnum}`;
|
||||
|
||||
/**
|
||||
* A value passed as a log argument after the message.
|
||||
*
|
||||
* Prefer a zero-argument function for expensive payloads: it is only invoked
|
||||
* when the event is actually emitted, so suppressed logs avoid the work.
|
||||
* The factory may be `async` or otherwise return a `Promise`; top-level
|
||||
* thenables are settled before sinks see the event (fire-and-forget).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* logger.debug("state", () => expensiveSnapshot());
|
||||
* logger.debug("response", async () => ({ data: await res.json() }));
|
||||
* ```
|
||||
*/
|
||||
export type LogData = unknown | (() => unknown);
|
||||
export type LogData = unknown | (() => unknown | Promise<unknown>);
|
||||
|
||||
/**
|
||||
* Per-call options for `trace` / `debug` / `log` / `info` / `warn` / `error`
|
||||
@@ -73,10 +78,13 @@ export interface LogEvent {
|
||||
namespace?: string;
|
||||
/**
|
||||
* Evaluated arguments for the event (call options already stripped).
|
||||
* Lazy `() => unknown` functions have already been invoked.
|
||||
* Lazy factories have been invoked and top-level thenables settled;
|
||||
* rejection reasons appear in place of rejected thenables.
|
||||
*/
|
||||
arguments: readonly unknown[];
|
||||
/** Wall-clock time when the event was created. */
|
||||
/**
|
||||
* Wall-clock time when the log call was made (before awaiting thenables).
|
||||
*/
|
||||
timestamp: Date;
|
||||
/** Deployment stage from {@link LoggerOptions.environment}. */
|
||||
environment: LoggerEnvironment;
|
||||
@@ -95,6 +103,11 @@ export interface LogEvent {
|
||||
* should be rendered by console-oriented sinks.
|
||||
*/
|
||||
sendToConsole: boolean;
|
||||
/**
|
||||
* `true` when emit was deferred to settle top-level thenables.
|
||||
* Omitted for fully synchronous emits. Console sinks render `[async]`.
|
||||
*/
|
||||
async?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user