npm install logfox
Express app file:
varexpress =app =config =logWriter = new configLogginglog = LogWriterexpressPassId = configexpressPassId;//stop app when something bad happened to loggerlogWriterstart;logWriter;applog = logWriter;//stop writing logs when app exitsprocess;app;//writing application logs:applog;app;//writing request logsapp;
App should handle it by itself, to force log writer to update file (for example if you rotated it),
kill -1 PID (
SIGHUP) and add code like this:
What can we log?
You can log any number of string and objects. String will be concatinated in
objects will be joined as array
data and serialized to JSON.
This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're config an error.
Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a 'hey, this happened, and it's weird, we should look into it.'
Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.
Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.
Use this when you want to go absolutely nuts with your config. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.
Use this when you want to log things which should not be logged - like user cridentials, crazy data amounts, etc. This config should be removed before pushing to production.