src/index.js
function useDefaultLogger (opts) {
  const {
    infoFile, errFile,
    append = true,
    timestamp = true, // string for a date format or pass true to use default format
  } = opts

  // The value of `logToConsole` default to true in dev mode
  let logToConsole = opts.logToConsole
  if (isDev() && !isDefined(logToConsole)) {
    debug('In dev mode and `logToConsole` is set to true.')

    logToConsole = true
  }

  const flag = append ? 'a' : 'w'
  const infoStream = infoFile && fs.createWriteStream(infoFile, { flags: flag })
  const errStream = errFile && fs.createWriteStream(errFile, { flags: flag })

  const infoRecorder = streamRecorder()
  const errRecorder = streamRecorder()

  return {
    verbose () {
      let stream = infoRecorder(infoFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stdout, stream ]

      createLogger(stream, 'Verbose', timestamp).apply(this, arguments)
    },
    info () {
      let stream = infoRecorder(infoFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stdout, stream ]

      createLogger(stream, 'Info', timestamp).apply(this, arguments)
    },
    warning () {
      let stream = errRecorder(errFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stderr, stream ]

      createLogger(stream, 'Warning', timestamp).apply(this, arguments)
    },
    error () {
      let stream = errRecorder(errFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stderr, stream ]

      createLogger(stream, 'Error', timestamp).apply(this, arguments)
    }
  }
}
function useDefaultLogger (opts) {
  const {
    infoFile, errFile,
    append = true,
    timestamp = true, // string for a date format or pass true to use default format
  } = opts

  // The value of `logToConsole` default to true in dev mode
  let logToConsole = opts.logToConsole
  if (isDev() && !isDefined(logToConsole)) {
    debug('In dev mode and `logToConsole` is set to true.')

    logToConsole = true
  }

  const flag = append ? 'a' : 'w'
  const infoStream = infoFile && fs.createWriteStream(infoFile, { flags: flag })
  const errStream = errFile && fs.createWriteStream(errFile, { flags: flag })

  const infoRecorder = streamRecorder()
  const errRecorder = streamRecorder()

  return {
    verbose () {
      let stream = infoRecorder(infoFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stdout, stream ]

      createLogger(stream, 'Verbose', timestamp).apply(this, arguments)
    },
    info () {
      let stream = infoRecorder(infoFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stdout, stream ]

      createLogger(stream, 'Info', timestamp).apply(this, arguments)
    },
    warning () {
      let stream = errRecorder(errFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stderr, stream ]

      createLogger(stream, 'Warning', timestamp).apply(this, arguments)
    },
    error () {
      let stream = errRecorder(errFile, name => fs.createWriteStream(name, { flags: flag }))
      if (logToConsole) stream = [ process.stderr, stream ]

      createLogger(stream, 'Error', timestamp).apply(this, arguments)
    }
  }
}
function useDefaultLogger ( opts ) { const { infoFile , errFile , append = true , timestamp = true , // string for a date format or pass true to use default format } = opts // The value of `logToConsole` default to true in dev mode let logToConsole = opts . logToConsole if ( isDev ( ) && ! isDefined ( logToConsole ) ) { debug ( 'In dev mode and `logToConsole` is set to true.' ) logToConsole = true } const flag = append ? 'a' : 'w' const infoStream = infoFile && fs . createWriteStream ( infoFile , { flags : flag } ) const errStream = errFile && fs . createWriteStream ( errFile , { flags : flag } ) const infoRecorder = streamRecorder ( ) const errRecorder = streamRecorder ( ) return { verbose ( ) { let stream = infoRecorder ( infoFile , name => fs . createWriteStream ( name , { flags : flag } ) ) if ( logToConsole ) stream = [ process . stdout , stream ] createLogger ( stream , 'Verbose' , timestamp ) . apply ( this , arguments ) } , info ( ) { let stream = infoRecorder ( infoFile , name => fs . createWriteStream ( name , { flags : flag } ) ) if ( logToConsole ) stream = [ process . stdout , stream ] createLogger ( stream , 'Info' , timestamp ) . apply ( this , arguments ) } , warning ( ) { let stream = errRecorder ( errFile , name => fs . createWriteStream ( name , { flags : flag } ) ) if ( logToConsole ) stream = [ process . stderr , stream ] createLogger ( stream , 'Warning' , timestamp ) . apply ( this , arguments ) } , error ( ) { let stream = errRecorder ( errFile , name => fs . createWriteStream ( name , { flags : flag } ) ) if ( logToConsole ) stream = [ process . stderr , stream ] createLogger ( stream , 'Error' , timestamp ) . apply ( this , arguments ) } } }
Construct a default logger, it can record the verbose, info , warning, error message and
write it to the file you specified.

Options:
infoFile: Path of the file for recording verbose and info message.
errFile: Path of the file for recording warning and error message.
append: Decide append or truncate the file if it exists. Default to be true.
timestamp: Represents the date format or pass true to use default format.

@param {object} opts - options
@returns {object} The logger
Construct a default logger it can record the verbose info warning error message and write it to the file you specified .