Log
sourceThe standard logger for all CartaX services.
Constructors
new Log(): Log
Properties
debugEnabled: booleansource
format: LogFormattersource
tagInjectors: TagInjector[]source
Methods
Static methods
addTagInjector(injector: TagInjector): voidsource
debug(message: string, tags: Tags): voidsource
Log a debug message. Use this for messages that are only useful during development and would not be useful when diagnosing a production issue. If in doubt, use info instead.
The message will only be printed if debug-level logging has been enabled by calling setDebugEnabled.
enquoteMaybe(value: string | Object): stringsource
If text contains spaces, returns the value of text surrounded by double-quote characters, with double-quotes already in the string escaped using backslashes. If there are no spaces, returns the original string unchanged.
error(message: string, tags: Tags): voidsource
Log an error message.
fatal(message: string, tags: Tags): voidsource
Log a fatal error message. Use this when the application cannot proceed and must shut down.
formatCaller(): stringsource
Returns the file and line number of a caller of this function, looking up through the stack to find the first frame that doesn't look like it's part of the logging infrastructure.
formatInjectedTags(): string[]source
formatTagsMaybe(tags: Tags): string[]source
Format a collection of message tags (key/value pairs) for printing. K/V pairs are formatting in logfmt style (key=value). Values are quoted if they contain spaces; if quoted, quotes within the string are escaped with a backslash character.
If a trace context is active, the trace and span ID will also be included in the returned string.
info(message: string, tags: Tags): voidsource
Log an informational message.
print(level: string, message: string, tags: Tags): voidsource
Format and print a message of a given log level, with an optional collection of message tags.
proxy<In extends any[], Out extends any[]>(loggerFn: Function, transformerFn: Function): Functionsource
Creates a proxy function that receives a set of arguments and returns them in a form that can be passed to a standard logging method. Use this to wrap a standard logger function without causing the wrapper to appear as the caller in the printed message.
The transformer function can take any arguments but must return a tuple that corresponds to the arguments of the logger function being proxied.
For example:
const transform = (...message: string[]) => [message.join(" ")] as const;
const error = Log.proxy(Log.error, transform);
error("a message", "that will", "be joined together");
render(level: string, message: string, tags: Tags): stringsource
Format a message of a given log level, with an optional collection of message tags.
setDebugEnabled(enabled: boolean = true): voidsource
Configure whether or not debug messages are emitted.
setFormatter(formatter: LogFormatter): voidsource
Configure the formatter.
warn(message: string, tags: Tags): voidsource
Log a warning message.