Logger

Enable shared and custom logging in your applications.

/* @runkit */
// register extension
const Logger = Grown.use(require('@grown/logger'));

Logger.getLogger().info('This works?');
Logger.setLevel('debug');

// always show, not restricted by level
Logger.message('OK');
Logger.error('ERROR');

// register middleware
server.plug(Grown.Logger);

// use with server
server.mount(conn => {
  // shown, because `debug > info`
  conn.logger.info('INFO');
  conn.logger.debug('DEBUG');

  // not shown, because `verbose > debug`
  conn.logger.verbose('VERBOSE');
});

Click ► RUN and try requesting through this link.

Methods mixin

  • logger — Log-pose instance, see docs
    • isEnabled() — Returns if logging is globally enabled.
    • isVerbose(), isDebug() and isInfo() — Returns true if log-level is enabled, respectively.
    • printf(...) and write(...) — Low-level methods from log-pose internals
    • verbose(...), debug(...) and info(...) — High-level methods from log-pose

Public methods static

  • $before_render(ctx, template) — Append or replace {elapsed} on the response body, only if Render is available
  • $before_send(e, ctx) — Hook for calculating the {elapsed} time before sending anything, see above
  • $install(ctx) — Used by server.plug calls.
  • $mixins() — Extra Grown.Conn.Builder definitions.
  • message(...) and error(...) — Standard logging helpers.
  • pause() and resume() — To turn off/on logging respectively.
  • setLevel(type) — Set active level of logging.
  • setLogger([stdout]) — Define output target (default to process.stdout)
  • getLogger(depth[, stdout]) — Return shared logger instance, optional output as above
  • newLogger(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.

➯ Next: Extensions ⟩ Model