Playo-logger
It will create logs winston according to services
It will delete logs before 30 days
PASS SERVER=production
to skip debug logs
Log Levels
- alert (Highest Priority)
- error
- info
- debug
How to use
-
Basic Logger create one logger file and add
const PlayoLogger = require("@playo/logger"); const Logger = new PlayoLogger("<service-name>"); module.exports = Logger;
It will create
<service-name>-YYYY-MM-DD-info
,<service-name>-YYYY-MM-DD-error
,<service-name>-YYYY-MM-DD-debug
file in/var/log/playo
folder -
Store Logs in Different Path
const PlayoLogger = require("@playo/logger"); const Logger = new PlayoLogger("<service-name>", "<path-name>"); module.exports = Logger;
It will create
<service-name>-YYYY-MM-DD-info
,<service-name>-YYYY-MM-DD-error
,<service-name>-YYYY-MM-DD-debug
file in<path-name>
folder -
Mail Logger
const PlayoLogger = require("@playo/logger"); const Logger = new PlayoLogger("<service-name>"); Logger.setMailer({ 'receiverEmail': ["test@mail.com"], // array of recievers, mandatory 'senderEmail': "logger@mail.com" // address of sender, mandatory 'senderName': 'Mail Logger' // default: Mail Logger, optional 'replyEmail': 'no-reply@mail.com' // default: no-reply@playo.co, optional 'region': "us-east-1", // default: 'us-east-1', optional }); module.exports = Logger;
Env Variables
AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
-
Slack Logger
const PlayoLogger = require("@playo/logger"); const Logger = new PlayoLogger("<service-name>"); Logger.setSlack("<channel>"); // <channel> is optional, default is 'general' module.exports = Logger;
Env Variables
SLACK_TOKEN
-
Custom keys
const PlayoLogger = require("@playo/logger"); const Logger = new PlayoLogger("<service-name>"); Logger.set(key, value); module.exports = Logger;
set
can be used in the file which requires the logger instance
Example with mail and slack Logger
const PlayoLogger = require("@playo/logger");
const Logger = new PlayoLogger("utils");
Logger.setSlack("server_alerts");
Logger.setMailer({
receiverEmail: ["test@mail.com"], // array of recievers, mandatory
senderEmail: "logger@mail.com" // address of sender, mandatory
});
module.exports = Logger;
Pass Env for mail and slack logger
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
SLACK_TOKEN
How to Log
Logger.debug(id, data, message);
Logger.info(id, data, message);
Logger.error(id, data, message);
On Critical Logs, Put both error and alert log
Logger.alert(id, data, message);
Logger.error(id, data, message);