Log
const { log } = require('decorators')
class Logged {
@log({ traceResult: true, environment: 'development'})
logMe() {
return 'logged!'
}
@log({format: ({ className, methodName, lineNumber}) => `${className}.${methodName} @ ${lineNumber}` })
logFormatted() {
}
}
new Logged().logMe()
new Logged().logFormatted()
// $ mdctl tail --format=yaml
//
// timestamp: '2020-02-18T19:55:05.308Z'
// level: info
// message:
// - className: Logged
// methodName: logMe
// lineNumber: 5
// ms: 0.080908203125
// result: logged!
//
// timestamp: '2020-02-18T19:55:05.312Z'
// level: info
// message:
// - Logged.logFormatted @ 10
@log(options)
Arguments
options
{ Object } Options object.target
{ String = "console" }logger
logs to the developer log,console
logs to the console stream, accessibleusing
mdctl tail
(see https://www.npmjs.com/package/@medable/mdctl-cli). Possible values (logger, console).level
{ String = "info" } The log level to use. Possible values (logger: ['warn', 'error', 'info', 'debug', 'trace'],console: ['warn', 'error', 'info'] ).
traceError
{ Boolean = false } If true, logs errors thrown from the method.traceResult
{ Boolean = false } If true, logs the method return value.roles
{ String[] | ObjectID[] = "*"} Limits logging to a list of rolesenvironment
{ String = "*" } Limits logging to an environment. Possible values (*, production, development).format
{ Function } A function to transform the log output. Takes a single argument (function(log) { return log }
)
Last updated
Was this helpful?