Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.


Action "log.fs"

Write log to the host filesystem in a user provided format.


By default, a file name "{}.log" over SSH or "local.log" will be created inside the base directory defined by the option "basedir". The path looks like "{config.basedir}/{config.filename}.log".

If the option "archive" is activated, a folder named after the current time is created inside the base directory. A symbolic link named as "latest" will point this is direction. The paths look like "{config.basedir}/{time}/{config.filename}.log" and "{config.basedir}/latest".


on_action =
  before: [
  after: [
  handler: ({config, ssh}) ->
    # With ssh, filename contain the host or ip address
    config.filename ?= "#{ssh?.config?.host or 'local'}.log"
    # Log is always local
    config.ssh = false

Schema definitions

definitions =
    type: 'object'
        type: 'boolean'
        default: false
        description: '''
        Save a copy of the previous logs inside a dedicated directory.
        type: 'string'
        # default: './log'
        description: '''
        Directory where to store logs relative to the process working
        directory. Default to the "log" directory. Note, when the `archive`
        option is activated, the log files will be stored accessible from
        type: 'string'
        description: '''
        Name of the log file. It could contain the directory path as well.
        It defaults to `local.log` locally or `{hostname}.log` on a remote
        type: 'object'
        description: '''
        An object of key value pairs where keys are the event types and the
        value is a function which must be implemented to serialize the
    required: ['serializer']


handler = ({config}) ->
  # Normalization
  logdir = path.dirname config.filename
  logdir = path.resolve config.basedir, logdir if config.basedir
  # Archive config
  if config.archive
    latestdir = path.resolve logdir, 'latest'
    now = new Date()
    config.archive = "#{now.getFullYear()}".slice(-2) + "0#{now.getFullYear()}".slice(-2) + "0#{now.getDate()}".slice(-2) if config.archive is true
    logdir = path.resolve config.basedir, config.archive
    await @fs.base.mkdir logdir, ssh: false
  catch err
    throw err unless err.code is 'NIKITA_FS_MKDIR_TARGET_EEXIST'
  # Events ?= fs.createWriteStream path.resolve logdir, path.basename config.filename
  await config
  # Handle link to latest directory
  await @fs.base.symlink
    $if: latestdir
    source: logdir
    target: latestdir


module.exports =
  handler: handler
    on_action: on_action
    definitions: definitions


fs = require 'fs'
path = require 'path'
Edit on GitHub

Nikita is an open source project hosted on GitHub and developed by Adaltas.