Logger ✎
Enable shared and custom logging in your applications.
// register extension
const Logger = Grown.use(require('@grown/logger'));
Logger.getLogger().info('This works?');
Logger.setLevel('debug');
// access through utils
Grown.use((_, util) => {
util.getLogger().printf('\r{%ok 42%}\n');
});
// always show, not restricted by level
Logger.message('OK');
Logger.error('ERROR');
// register middleware
server.plug(Grown.Logger);
// use with server
server.mount(conn => {
conn.res.end('DONE');
// shown, because `debug > info`
conn.logger.info('INFO');
conn.logger.debug('DEBUG');
// not shown, because `verbose > debug`
conn.logger.verbose('VERBOSE');
});
Click ▷ RUN above and then try requesting through
this link
below.
Methods mixin
logger
— Log-pose instance, see docsisEnabled()
— Returns if logging is globally enabled.isVerbose()
,isDebug()
andisInfo()
— Returns true if log-level is enabled, respectively.printf(...)
andwrite(...)
— Low-level methods from log-pose internalsverbose(...)
,debug(...)
andinfo(...)
— High-level methods from log-pose
Public methods static
$before_render(ctx, template)
— Append or replace{elapsed}
on the response body, only ifRender
is available$before_send(e, ctx)
— Hook for calculating the{elapsed}
time before sending anything, see above$install(ctx)
— Used byserver.plug
calls.$mixins()
— ExtraGrown.Conn.Builder
definitions.message(...)
anderror(...)
— Standard logging helpers.pause()
andresume()
— To turn off/on logging respectively.setLevel(type)
— Set active level of logging.setLogger([stdout])
— Define output target (default toprocess.stdout
)getLogger(depth[, stdout])
— Return shared logger instance, optional output as abovenewLogger(prefix, level, depth[, stdout])
— Returns a custom log-pose interface
Private* methods static
_elapsedTime()
— Used by$before_render
._errorLog(value)
— Override output for errors._msgLog(value)
— Override output for regular logs.