Skip to content

Error on usage with Sails.js v1.0.2 #1501

Description

@pahan35

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: 8.12.0
  • Operating System? Windows
  • Language? ES7

What is the problem?

  1. Install clean Sails.js v1.0.2 project
npm i -g sails@1.0.2
sails new app-name
cd app-name
  1. Install winston
npm i --save winston
  1. Setup log to use new winston logger
    3.1. Open config/log.js
    3.2 Replace content with next code
/**
 * Built-in Log Configuration
 * (sails.config.log)
 *
 * Configure the log level for your app, as well as the transport
 * (Underneath the covers, Sails uses Winston for logging, which
 * allows for some pretty neat custom transports/adapters for log messages)
 *
 * For more information on the Sails logger, check out:
 * https://sailsjs.com/docs/concepts/logging
 */

const {createLogger, format, transports} = require('winston');
const { colorize, combine, simple } = format;
const options = {
  console: {
    format: combine(
      colorize({level: true}),
      simple(),
    ),
    level: 'silly'
  },
};

const customLogger = createLogger({
  format: simple(),
  transports: [
    new (transports.Console)(options.console),
  ]
});

module.exports.log = {

  /***************************************************************************
  *                                                                          *
  * Valid `level` configs: i.e. the minimum log level to capture with        *
  * sails.log.*()                                                            *
  *                                                                          *
  * The order of precedence for log levels from lowest to highest is:        *
  * silly, verbose, info, debug, warn, error                                 *
  *                                                                          *
  * You may also set the level to "silent" to suppress all logs.             *
  *                                                                          *
  ***************************************************************************/

  custom: customLogger,
  level: 'silly',

  // Disable captain's log so it doesn't prefix or stringify our meta data.
  inspect: false

};

What is the problem?

It fails with error on this line due to empty sails.log.silly() call on the line which is used to make an empty line only on silly log level

What do you expect to happen instead?

I expect to run app successfully as it was on winston@2

Other information

It can easily be fixed by extending condition in the line
from if (arguments.length === 1) { toif (arguments.length === 1 && typeof level === 'object') {.

I've done it locally ATM but unfortunately I won't have this changes when I will be deploying my app somewhere else.

If you wish, I can make a PR with this noticed change.

Thanks for your attention!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions