Search…
Log
Logs Class Methods
1
const { log } = require('decorators')
2
3
class Logged {
4
5
@log({ traceResult: true, environment: 'development'})
6
logMe() {
7
return 'logged!'
8
}
9
10
@log({format: ({ className, methodName, lineNumber}) => `${className}.${methodName} @ ${lineNumber}` })
11
logFormatted() {
12
}
13
14
}
15
16
new Logged().logMe()
17
new Logged().logFormatted()
18
19
// $ mdctl tail --format=yaml
20
//
21
// timestamp: '2020-02-18T19:55:05.308Z'
22
// level: info
23
// message:
24
// - className: Logged
25
// methodName: logMe
26
// lineNumber: 5
27
// ms: 0.080908203125
28
// result: logged!
29
//
30
// timestamp: '2020-02-18T19:55:05.312Z'
31
// level: info
32
// message:
33
// - Logged.logFormatted @ 10
Copied!

@log(options)

Arguments
  • options { Object } Options object.
    • target { String = "console" } logger logs to the developer log, console logs to the console stream, accessible
      using 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 roles
    • environment { 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 modified 2mo ago
Copy link