Wrap function that returns an Universal function that is enabled with logging.
Usage:
const wrap = require('@adobe/helix-shared-wrap');
const { logger } = require('@adobe/helix-universal-logger');
async function main(req, context) {
const { log } = context;
//…my action code…
log.info('.....');
}
module.exports.main = wrap(main)
.with(logger.trace)
.with(logger);- logger
- ~init(context, [logger], [level]) ⇒
SimpleInterface - ~cleanupHeaderValue(value) ⇒
- ~trace(fn) ⇒
UniversalFunction - ~logger(fn, [opts]) ⇒
function
- ~init(context, [logger], [level]) ⇒
Initializes helix-log that adds additional activation related fields to the loggers. It also looks for credential params and tries to add additional external logger (eg. coralogix).
It also initializes context.log with a SimpleInterface if not already present.
Kind: inner method of logger
Returns: SimpleInterface - the helix-log simple interface
| Param | Type | Default | Description |
|---|---|---|---|
| context | UniversalContext |
universal function context | |
| [logger] | MultiLogger |
rootLogger |
a helix multi logger. defaults to the helix rootLogger. |
| [level] | string |
Overall log-level. defaults to params.LOG_LEVEL or 'info`. |
Cleans up a header value by stripping invalid characters and truncating to 1024 chars
todo: use the one from helix shared
Kind: inner method of logger
Returns: a valid header value
| Param | Type | Description |
|---|---|---|
| value | string |
a header value |
Creates a tracer function that logs invocation details on trace level before and after the
actual action invocation.
Kind: inner method of logger
Returns: UniversalFunction - an action function instrumented with tracing.
| Param | Type | Description |
|---|---|---|
| fn | UniversalFunction |
original OpenWhisk action main function |
Wrap function that returns an universal function that is enabled with logging.
Kind: inner method of logger
Returns: function - a the wrapped function.
| Param | Type | Description |
|---|---|---|
| fn | UniversalFunction |
original universal main function |
| [opts] | WrapOptions |
optional options. |
Example
const wrap = require('@adobe/helix-shared-wrap');
const { logger } = require('@adobe/helix-universal-logger');
async function main(req, context) {
const { log } = context;
//…my action code…
log.info('.....');
}
module.exports.main = wrap(main)
.with(logger.trace)
.with(logger);