Winston: Add a Logger instance to winston.loggers

Created on 16 Apr 2015  ·  3Comments  ·  Source: winstonjs/winston

I am trying to to create multiple loggers by doing

winston.loggers.add('category1', {})

I thought to create new loggers by "new winston.Logger" and then adding them like this:

myNewLogger = new winston.Logger({transport: [...]})
winston.loggers.add('category1', myNewLogger)

but the Logger is changing the transports to an object instead on an array which causes an exception in
container.js line 52: options.transports = existing ? existing.slice() : [];

because an object does not have a slice method

thanks

faq

Most helpful comment

Why does winston.loggers.add('category1', {level: "error"}) not work? It treats "level" as transport, but I will use the default transport of main logger.

All 3 comments

The winston.loggers.add method expects options to be passed to a new Logger instance, not a Logger instance itself. e.g.: this will work

winston.loggers.add('category1', { transports: [/* Your transports etc */] })

Why does winston.loggers.add('category1', {level: "error"}) not work? It treats "level" as transport, but I will use the default transport of main logger.

@ChristophAtAdlos did you ever figure out why this was? Having the same issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlank picture jlank  ·  4Comments

alditis picture alditis  ·  3Comments

anks333 picture anks333  ·  3Comments

greenhat616 picture greenhat616  ·  3Comments

xungwoo picture xungwoo  ·  3Comments