node package manager

oh-my-log

oh-my-log version License

Beautiful console logs for your console applications with string substitution using fürmat & styling with Chalk.

Build Status Downloads Code Climate Coverage Status Dependency Status Dependencies

Install

npm install --only=production --save oh-my-log

API

myLog(name, [options])

  • name (String, Required): The name/label to use
  • options (Object, Optional): An optional options object may be passed that alters certain behaviours

Returns: Function The logging function

const logger = require('oh-my-log')
const log = logger('😄')
 
log('foo')

The above example will output:

example

  • Create custom local variables:

    const log = logger('😄', {
      locals: {
        me: 'ahmad'
      }
    })
     
    log('Hi, I\'m %me. repeat, my name is %me') // outputs: `Hi, my name is ahmad. repeat, my name is ahmad` 
  • Supports creating custom modifiers:

    const log = logger('😄', {
      modifiers: {
        upper: (string) => string.toUpperCase()
      }
    })
     
    log('%s:upper', 'foo') // outputs `FOO` 
  • Use chained Chalk styles as modifiers:

    const log = logger('😄')
     
    log('%s:red:bold', 'foo')
  • Combine for extra magic:

    const log = logger('😄', {
      locals: {
        me: 'ahmad'
      },
      modifiers: {
        upper: (string) => string.toUpperCase()
      }
    })
     
     
    log('Hi, I\'m %me:upper. repeat, my name is %me:upper:red:bold') // outputs a colored version of: `Hi, my name is ahmad. repeat, my name is ahmad` 

Options

Name Type Required Description Default
prefix String ✖️ prefix this string after substitution with locals values using fürmat [%name] %date:
locals Object ✖️ locals object, see fürmat for details false
modifiers Object ✖️ custom modifiers, see fürmat for details {}
chalk Boolean ✖️ enable/disable chalk modifiers support see fürmat for details true
date String ✖️ any dateformat compatible value hh:MM:ss TT
func Function ✖️ The logging function console.log

fürmat & Chalk

oh-my-log relies heavily on fürmat for styling text (using chalk) and adding modifiers functions for extended formating, please review fürmat and chalk documentation for more details on how to use those modules.

oh-my-log will also look for options object in your package.json file. This is accomplished using pkg-config, refer to pkg-config's README for more info


©️ ahmadnassri.com  ·  License: ISC  ·  Github: @ahmadnassri  ·  Twitter: @ahmadnassri