Testing and Bunyan

1,593 views
Skip to first unread message

camp...@okcupidlabs.com

unread,
Apr 12, 2013, 7:20:56 PM4/12/13
to bunyan-...@googlegroups.com
I am using bunyan in several projects now (primarily http servers) and was wondering what the ideal way/ recommended ways to handle test scenarios and logging. 

In some of my test cases I am intentionally triggering errors and then seeing bunyan output in my test output.

I was thinking that making a custom stream for test cases that should be silent might be the way to go...

Thoughts?

- jason

Trent Mick

unread,
Apr 12, 2013, 8:05:22 PM4/12/13
to camp...@okcupidlabs.com, bunyan-...@googlegroups.com
Not sure I understand. You want to use bunyan output as a way to track what has been done in the server and use that for asserting in tests that X was done?

In my usage I haven't typically used the logging output as a way to test that the server performed as expected. If doing so, I'd have the server be configurable to take a given logger. And then, as you suggest, use a custom stream for test cases.

Trent

--
Trent Mick

Jason Campbell

unread,
Apr 12, 2013, 10:00:30 PM4/12/13
to Trent Mick, bunyan-...@googlegroups.com
To be more clear, a problem I have run into is having bunyan's output leak into my test runner's output.

http://cl.ly/image/2A2G10083K0n


So I am not really wanting to use the output as much as I am wanting to prevent it from streaming to stdout/stderr, especially where I am intentionally testing situations that would call bunyan at the error level. 


- j

Trent Mick

unread,
Apr 13, 2013, 1:37:34 AM4/13/13
to Jason Campbell, bunyan-...@googlegroups.com
Ah, I see. I'd do one of the following:

- If your test setup starts your server programmatically, I'd make it possible to pass in a logger and then pass in a logger instance with no output streams. E.g.

var server;

function setup() {
    var log = bunyan.createLogger({name: 'testing', streams: []});
    server = createServer({log: log, ...});
}

function testOne() {
    // use `server` ...
    log.fatal('hi');  // this should go nowhere
}


- Or, if your server allows specifying a config file, then have a test config file with logging turned off or (as a workaround) with logging set to bunyan.FATAL level.  (Aside: I've been meaning to add a `bunyan.OFF` "level".)

- Otherwise, I'd write my server to take an envvar to turn off logging.  MYAPP_NO_LOGGING=1 or something. Then set that in the test runner.


Cheers,
Trent




--
Trent Mick

Jason Campbell

unread,
Apr 13, 2013, 9:28:02 PM4/13/13
to Trent Mick, bunyan-...@googlegroups.com
This is great, thanks! I think I will end up running with your first suggestion. 

Looking forward to the `bunyan.OFF` level as well.

- j

Matt

unread,
Oct 2, 2014, 6:01:48 PM10/2/14
to bunyan-...@googlegroups.com, tre...@gmail.com, camp...@okcupidlabs.com
I'm using bunyan in a project with similar needs, and saw this comment. After a cursory examination, I added simple support for bunyan.OFF in my local fork (https://github.com/mjk/node-bunyan/compare/trentm:5598700713c2fbb9ecb745d7b5fbb8ddc88cacc9...master).

Not sure if this is woefully naive or sufficient, so I haven't submitted a pull request. Happy to do so! 

Thanks for a great logger.
Matt

Marcello de Sales

unread,
Oct 20, 2014, 5:02:33 PM10/20/14
to bunyan-...@googlegroups.com, tre...@gmail.com, camp...@okcupidlabs.com
Hi Matt,

I was looking for something similar, but I think Environment variables are less intrusive than new levels. I'm coming from the Java world, where you can enable/disable logs per Logger object... For instance:

ComponentA
 - Uses Bunyan logger
 
ComponentB 
- Uses Bunyan Logger
- "include(ComponentA)"

My requirement is a way to turn ComponentA on/off during the execution of ComponentB based on any key of the log event object, say, "component": "componentA"... We could be looking for something like:

process.env.BUNYAN_LOG_DISABLE_componentA=true

Before logging, Bunyan would be looking at the set of keys "process.env.BUNYAN_LOG_DISABLE_*", and verify if the log event can be logged or not... 

If your pull request gets merged, I will submit one that takes environment variables that verifies whether the log event contains the given key prior to logging...

thanks!
Reply all
Reply to author
Forward
0 new messages