2.3.3 • Published 6 years ago

@hamistudios/footstep v2.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

footstep logo

footstep

footstep is a simple robust logger for nodejs

Build Status Coverage Status npm version license

Installation

$ npm install --save @hamistudios/footstep  

Documentation

Logger

Setup

const { Logger } = require("footstep");  
  
let logger = new Logger(options);  

Usage

logger.verbose("Hello World");  // => [10:34:35] verbose: Hello World
logger.info("Hello World");     // => [10:34:35] info: Hello World
logger.error("Hello World");    // => [10:34:35] error: Hello World
logger.warning("Hello World");  // => [10:34:35] warning: Hello World
logger.notice("Hello World");   // => [10:34:35] notice: Hello World
logger.debug("Hello World");    // => [10:34:35] debug: Hello World
logger.log("Hello World");      // => [10:34:35] log: Hello World

Options

Footstep comes with a lot of useful options to help customize your log messages including, custom streams, prefixes and functional expansions.

variablesdefaulttype
streams.verboseprocess.stdoutStream|Function
streams.infoprocess.stdoutStream|Function
streams.errorprocess.stderrStream|Function
streams.warningprocess.stdoutStream|Function
streams.noticeprocess.stdoutStream|Function
streams.debugprocess.stdoutStream|Function
streams.logprocess.stdoutStream|Function
streams.clearprocess.stdoutStream|Function
format{{date}} {{type}}: {{message}}String
formats.dateFunction() {}Function
formats.messageFunction() {}Function
formats.typeFunction() {}Function
prefixString
eolos.EOLString
debugfalseBoolean
verbosefalseBoolean
maxLogHistory50Integer
clearCodes.full\x1b[2JString
clearCodes.standard\x1b[0fString

Custom expansions

You can create custom function expansions by adding a new function to formats

const options = {
  format  : '[{{dow}}] {{message}}',
  formats : {
    dow     : function() {
      let days  = [ 'Sunday','Monday','Tuesday',
        'Wednesday','Thursday','Friday', 'Saturday' ],
      let date  = new Date();
      
      return days[date.getDay()];  
    }  
  }
};

let logger = new Logger(options);

logger.log('Hello World'); // => [Thursday] Hello World 

Streams

You can set the stream to anything with the instance of Stream including process.stdout, process.stderr, fs streams, HTTP streams etc.

Methods

.setVerbose

Set whether verbose logs should be sent to the stream.

Syntax
logger.setVerbose(boolean: value)

.setDebug

Set whether debug logs should be sent to the stream.

Syntax
logger.setDebug(boolean: value)

.clear

Clear the log output

Syntax
logger.clear(full: boolean)

.blank

Print a blank line to the specified stream

Syntax

logger.blank([StreamName: stream])

Example

logger.blank(StreamName.ERROR); // print a blank line to the error stream

.getPastLogs

Get an array of past logs (max log history specified via options.maxLogHistory)

Syntax

logger.getPastLogs()

.pad

Add padding to an array of strings to make them all the same length

Syntax

logger.pad(string[]: strings, [boolean: start=true])

Example

logger.pad(['test', 'testing']); // => ['   test', 'testing']
logger.pad(['test', 'testing'], false); // => ['test   ', 'testing']

.verbose

Print to the verbose stream

Syntax

logger.verbose(any[]: args)

Example

logger.verbose('Sum (5+5)', 10);

.info

Print to the info stream

Syntax

logger.info(any[]: args)

Example

logger.info('Sum (5+5)', 10);

.error

Print to the error stream

Syntax

logger.error(any[]: args)

Example

logger.error('Sum (5+5)', 10);

.warning

Print to the warning stream

Syntax

logger.warning(any[]: args)

Example

logger.warning('Sum (5+5)', 10);

.notice

Print to the notice stream

Syntax

logger.notice(any[]: args)

Example

logger.notice('Sum (5+5)', 10);

.debug

Print to the debug stream

Syntax

logger.debug(any[]: args)

Example

logger.debug('Sum (5+5)', 10);

.log

Print to the log stream

Syntax

logger.log(any[]: args)

Example

logger.log('Sum (5+5)', 10);

Colors

Footstep has built in support for colors and styles, you can use these to bring your logs to life.

Usage

const { Colors } = require("footstep");

console.log('I am red and underlined'.red.underline);  
console.log('I am blue and bold'.blue.bold);  
console.log('I am black with a white background'.black.bg_white);  
console.log('I am black with a red background'.red.inverse);
console.log(color.strip('I am no color'.yellow));

List of colors & styles

  • .reset
  • .black
  • .red
  • .green
  • .yellow
  • .blue
  • .magenta
  • .cyan
  • .white
  • .gray
  • .gray
  • .bright_black
  • .bright_red
  • .bright_green
  • .bright_yellow
  • .bright_blue
  • .bright_magenta
  • .bright_cyan
  • .bright_white
  • .bg_black
  • .bg_red
  • .bg_green
  • .bg_yellow
  • .bg_blue
  • .bg_magenta
  • .bg_cyan
  • .bg_white
  • .bright_bg_black
  • .bright_bg_red
  • .bright_bg_green
  • .bright_bg_yellow
  • .bright_bg_blue
  • .bright_bg_magenta
  • .bright_bg_cyan
  • .bright_bg_white
  • .bold
  • .faint
  • .italic
  • .underline
  • .slow_blink
  • .rapid_blink
  • .inverse
  • .hidden
  • .strikethrough
  • .framed
  • .encircled
  • .overlined
2.3.3

6 years ago

2.2.1

6 years ago

2.1.1

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago