Showing posts with label logger. Show all posts
Showing posts with label logger. Show all posts
Friday, 1 May 2020
Thursday, 16 January 2020
Winston logger with file name and time stamp nodejs
logger.js
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const path = require('path');
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});
const getLabel = function(callingModule) {
const parts = callingModule.filename.split('/');
return path.join(parts[parts.length - 2], parts.pop());
};
const logger = (callingModule)=> createLogger({
format: combine(
label({ label: getLabel(callingModule) }),
timestamp(),
myFormat
),
transports: [new transports.Console()]
});
module.exports = {
logger:logger
}
use as below:
const logger = require('../util/logger').logger(module);
logger.info('logger file..');
//util/logger is my file path of logger.js
output:
2020-01-16T08:28:41.893Z [controller/shop.js] info: logger file..
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const path = require('path');
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});
const getLabel = function(callingModule) {
const parts = callingModule.filename.split('/');
return path.join(parts[parts.length - 2], parts.pop());
};
const logger = (callingModule)=> createLogger({
format: combine(
label({ label: getLabel(callingModule) }),
timestamp(),
myFormat
),
transports: [new transports.Console()]
});
module.exports = {
logger:logger
}
use as below:
const logger = require('../util/logger').logger(module);
logger.info('logger file..');
//util/logger is my file path of logger.js
output:
2020-01-16T08:28:41.893Z [controller/shop.js] info: logger file..
Subscribe to:
Posts (Atom)
links for Data Structure
1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭: https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...
-
1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭: https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...
-
We start producing messages to Kafka by creating a ProducerRecord, which must include the topic we want to send the record to and a value. O...
-
Kafka Architecture Kafka consists of Records, Topics, Consumers, Producers, Brokers, Logs, Partitions, and Clusters. Records can have key...