1

Is there a way by which I can turn on/off certain logs, based on its type/levels.

For eg: I have defined 3 levels: ALL, WARNING, CRITICAL

And I have my Log class, where I will set this. Say I set Level: 'ALL' So this will log everything, wherever I have logged messages.

Now, when I set Level: 'WARNING' This will only log messages, which are of warning type.

Can I do this with Bunyan ? Or any other module?

Please help !!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Anish Nair
  • 3,238
  • 29
  • 41
  • 1
    https://github.com/trentm/node-bunyan#levels – robertklep Jun 24 '15 at 06:57
  • Thank you for your reply. But while the app is running, and say if the log-file is filling very fast. And I decide, I want to log only `warn` and `fatal` logs.. So how do I do that? Where do I change that from?? P.S. I know about log-rotation, but still. – Anish Nair Jun 24 '15 at 07:28
  • 1
    You can use `logger.level('warn')` to log everything from `warn` "upwards" (that is, `warn`, `error` and `fatal` only). – robertklep Jun 24 '15 at 07:29

2 Answers2

1

One work around would be to use Bunyan's DTrace facilities.Keep the log level higher and if you need to inspect low level log like debug you can run Dtrace command Examples Trace all log messages coming from any Bunyan module on the system

dtrace -x strsize=4k -qn 'bunyan*:::log-*{printf("%d: %s: %s", pid, probefunc, copyinstr(arg0))}'

Trace all log messages coming from the "wuzzle" component:

dtrace -x strsize=4k -qn 'bunyan*:::log-*/strstr(this->str = copyinstr(arg0), "\"component\":\"wuzzle\"") != NULL/{printf("%s", this->str)}'

you need to manually install the "dtrace-provider" lib separately via npm install dtrace-provider Check out the documentation here

Sarfaraz Khan
  • 2,166
  • 2
  • 14
  • 29
-1

try using winston module for logging .this is good for logging and has log rotation and other features