Usually i’m using console API to logging or debugging stuff in my application, since i’m using pm2 as Process Manager, pm2 have their own Logging Management features, after many months & my apps have bigger user base, it’s become more harder to debug the application.
I searching for logging package, and found log4js, and i take a look, it’s quite simple to setup, and have a lot of integrations.
I want to share the easy way to setup log4js in my usual codebase.
On basic express.js app, this is the step i do to integrate log4js.
- Install the npm package and additional slack appender
npm install log4js @log4js-node/slack
2. Create the logging modules , i usually place it on <root_folder>/modules/logger.js
3.Write this code in logger.js
4. In your express.js app entry point, modify as you wish like this
5.Start logging by doing this
This articles heavily inspired by:
Node.js+Express.js+log4js — Qiita
https://qiita.com/cobachan/items/953a507c7eb772f7f5d8
[Node.js]Express4 + log4jsでロギング — Qiita
https://qiita.com/tnnsst35/items/7e7129c7758c9c560c41
log4jsの覚え書き — log4.jsを使ってみた — — Qiita
https://qiita.com/_daisuke/items/865cf929a403cc9eec53
[Nodejs] Express+Log4jsで実践的なログ出力を行う — YoheiM .NET
https://www.yoheim.net/blog.php?q=20130903
Enjoy logging your apps.