Closed megastef closed 5 years ago
+1. But how often are logs written to stdout/stderr?
Any updates on this one? I am using a morgan for logging the requests and I can't figure it out how to ship those logs to Logsene.
@istratievladut I see morgan can log to files. Is that what you are doing with morgan by any chance? If yes, you can use any log shipper, like e.g. https://github.com/sematext/logagent-js to ship logs. If you are logging to stdout/stderr, then I think https://github.com/sematext/spm-agent-nodejs doesn't have anything for that yet and the above was just @megastef showing how it could be done.
I find this feature still interesting because it would not need any log shipper and would not require any code change for logging (see examples below).
@istratievladut Using @sematext/logagent you could run node myapp.js | logagent -i YOUR_LOGSENE_TOKEN
.
And I see that morgan accepts writeable streams, and you could use winston-stream if you use already winston-logsene you could provide the write function to wrap the winston-logsene logger :
var winston = require('winston')
var logsene = require('winston-logsene')
var logger = new winston.Logger()
logger.add (logsene, {
token: process.env.LOGSENE_TOKEN,
type: 'test_logs',
url: 'https://logsene-receiver.sematext.com/_bulk'
})
var logseneStream = {
write: (message) => {
logger.info(message)
}
}
// for Express app ...
app.use(morgan('combined', {stream: logseneStream}))
If you use upstart or systemd your logs would be captured by those Linux services and could be shipped with Logagent or any other log shipper.
If you run your node app on docker stdout/stderr could be captured by Sematext Docker Agent
So there are several options until we find the time to implement Capture and ship log output
the problem with winston-logsene though is that it is out of date in how to use it. the code you provided does not work.
winston-logsene will get updated to work with Winston 3.x in https://github.com/sematext/winston-logsene/issues/15
We will not add log shipping. You can always collect logs from stdout with Logagent and run e.g. run node myapp.js | logagent -i logs_token -e https://logsene-receiver.sematext.com
In case you use upstart or systemd, this blog post might be helpful: https://www.nearform.com/blog/pino-the-fastest-node-js-logger-for-production/
If you run your app i containers, you can simply use Logagent for Docker: https://sematext.com/docs/logagent/installation-docker/
As metrics and logs belong together I suggest an option to capture stout and stderr of node apps and ship logs to Logsene without additional configuration of any log shipper.
Example to hook into stdout/stderr stream: https://gist.github.com/pguillory/729616