Open isaacs opened 12 years ago
How about attaching a formatter to a Logger stream? Or the (sub)Logger in general.
var log = new Logger({
name: "amon",
streams: [
{
level: "info",
stream: process.stdout,
formatter: "pretty"
},
{
level: "error",
stream: "./error.log" // Uses default JSON formatter
}
]
}
Getting closer. type == 'raw'
streams are going in soon (see issue #8).
Anything new here? This is the only feature I'm missing to fully use bunyan.
I have some work started on the 1.x branch, but it is a ways from being ready. I also have a looming deadline mid-December at work, so I probably won't get back to this until after then.
:+1: Yes, please!
+1. I've created a minimal writable stream that prints out the level/message and am using that for the time being. (Maybe there is a better workaround?)
Any updates on this?
I've been using a simple shell script to save those keystrokes:
#!/usr/bin/env sh
node . | bunyan -o short
But I had some free time so I tried writing a stream to pipe the output through bunyan
but ended up with a catch-22 situation, the spawned process only exits when the main process does and the main process only exits once the child does.
It should work if your main process is long running (web servers, etc) but isn't ideal for short running apps like cli tools.
var spawn = require('child_process').spawn;
var through = require('through');
var path = require('path');
var fs = require('fs');
var prettyStream = function(args) {
args = args || ['-o', 'short'];
var bin = path.resolve(path.dirname(require.resolve('bunyan')), '..', 'bin', 'bunyan');
var stream = through(function write(data) {
this.queue(data);
}, function end () {
this.queue(null);
});
if(bin && fs.existsSync(bin)) {
var formatter = spawn(bin, ['-o', 'short'], {
stdio: [null, process.stdout, process.stderr]
});
stream.pipe(formatter.stdin);
}
return stream;
};
bunyan.createLogger({
name: 'test',
stream: process.stdout.isTTY ? prettyStream() : process.stdout,
level: 'info'
});
@jameswyse unfortunately I haven't had a chance yet :(
I have a big release of work stuff in a couple weeks. I hope to get a chance for this ticket (among a few others) after that.
Whatever happened to this? Bunyan would be perfect if this were implemented. Needing to pipe to bunyan is quite annoying. I would switch everything to bunyan if it were not for this one issue.
+1
We have some command line utils which fetch JSON logs from the server, and I keep forgetting to pipe the result to bunyan. I wish something like this existed so we could (within the CLI client) check if output it to TTY and if so call bunyan.formatOutput(...) instead of just printing out the raw JSON.
+1
+1
+1 looking forward for this feature.
+1
This is the main thing that stops me from choosing bunyan
as a logger lib for my project, so +1!
@trentm Are you looking at this already or you still don't have time?
+1
I neeeeeeed this! +1
After trying out this logger package, this is one of the first features I found myself wanting and is the only one that is missing at the moment. Any news on where this might be at?
+1 any updates?
Nothing after 4 years?
To anyone still looking, this works well: https://github.com/mrrama/node-bunyan-prettystream
import bunyan from 'bunyan';
import PrettyStream from 'bunyan-prettystream';
const stream = new PrettyStream();
stream.pipe(process.stdout);
const logger = bunyan.createLogger({
name: 'npm-search',
streams: [{
stream,
}],
});
Or even this: https://github.com/benbria/bunyan-debug-stream
seems to work better
Now that bunyan-cli doesn't process ctrl+c/SIGINT anymore (in patch release!) this is even more important.
@trentm it's been a year since your last reference of this issue. More than 5 years since the issue was first opened. Would a PR be accepted? It seems this one is related: https://github.com/trentm/node-bunyan/pull/102
I just send this to a nodejs stream and manually console.log (assuming you have not overwritten console.log behavior)
let _stream = new stream.Writable()
let _log = bunyan.createLogger({
name: this._process_name,
level: this._log_level,
serializers: {
req: bunyan.stdSerializers.req
},
env: this._env
})
_stream._write = (chunk, encoding, next) => {
console.log(JSON.parse(chunk))
next()
}
_log.addStream({
name: 'some new stream',
stream: self._stream,
level: self._log_level,
serializers: {
req: bunyan.stdSerializers.req
},
env: this._env
})
Are there any updates to this? Would also like to use this in our CLI tool!
It's pretty common in development to do a lot of
node server.js
and watch the output. Piping that to bunyan is a bit annoying.It should default to doing the pretty stuff if process.stdout.isTTY === true.