Answer the question
In order to leave comments, you need to log in
Logger for NodeJS?
Friends, did anyone find a logger for NodeJS that would meet the following requirements:
1) Formatted output to a file (date, tag, etc.)
2) Possibility to replace the log file with a database in the future
3) Ability to send logs to another machine
4) Notifications to mail / SNS at a certain level of messages (for example, if the connection to the database is gone)
syslog would be ideal here (in my case, rsyslog), but ...
Now the problem is more detailed:
1) Ready-made solutions here , which I managed to get acquainted with, dump the task logging to the main precess, which is not justified.
For example winston, has a bunch of transports and formatting and a bunch of goodies, but this is all done in the main process of the application and log problems lead to application problems (this forced me to look for a more suitable solution).
Plus, winston until recently had broken file write compatibility and still has broken syslog compatibility. (NodeJS 9+)
2) Now the application is launched using forever , it redirects the standard output of the "worker" to files in the child process, which removes the burden and problems associated with logging. But we have only 3 log files and that's it, no formatting analysis and notifications.
3) It would be possible to read the Forever files and merge them into syslog (rsyslog can do it out of the box), but message levels (error, info, etc.) are lost, so there is no notification for them.
4) It would be possible to write to syslog immediately from the main process, but here we go to point 1 and logging problems become application problems.
I turn to the community for help, suddenly someone found a solution or a group of solutions, since he himself is already in despair =)
Answer the question
In order to leave comments, you need to log in
A year has passed, my own logger has been written and is being used. Below I want to describe the reasons and what happened.
The requirements have changed and now they perfectly fit the ideology of 12 factor app 12factor.net/logs
Namely: the logger and the application itself do not write the log either to the file or to the database. No transports. The log is written only to stdout.
Motivation:
1) We get a great console log during development just by running the application. Without any "developer" modes of transport.
2) In production, the collection and transport of the log is done by what launches our application (forever, upstart, supervisor). The process of transporting the log does not lie with the application itself - it frees hands to use both its own log aggregation services (logstash) and third-party ones (loggly).
2) Both the logger and the application itself are free from the bugs of the "fat" logger and transports.
Implementation requirements:
1) Quick start - the ability to start using the logger without initial configuration
2) Namespaces
3) Flexibility in customizing the format of messages (which we write to stdout)
This is how the mag logger turned out
Quick start
var logger = require('mag')();
logger.info('my great application is running!');
var mag = require('mag');
var logger = mag('my-app');
logger.info('my great application is running');
In general, with loggers in a node, not so much. We abandoned Winston a long time ago, because it stopped developing, and the developers did not even accept ready-made pull requests.
Your list didn't seem to have this github.com/nomiddlename/log4js-node . Now we use it. But it looks like something fell on the 0.6 version under the v0.10 node. Or streams in the top ten are crooked. The process works for me for about 15 minutes, and then it gains memory to the maximum and eats the entire processor core. We rolled back to the previous version of the log and node - everything is there without problems.
The only thing I can advise is to look for a package where you consider the architecture and code to be sane, and add your adapters to the logging methods.
Have you looked at Graylog2? graylog2.org/
There are bindings including for the node
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question