How to use the Logger function from winston
Find comprehensive JavaScript winston.Logger code examples handpicked from public code repositorys.
winston.Logger is a logger object in the Winston library for Node.js that provides customizable logging functionality.
995 996 997 998 999 1000 1001 1002 1003 1004
method: 'POST', path: '/javascript-errors', config: { handler: function (request, reply) { if (request.payload) { var logger = new winston.Logger({ transports: [ new winston.transports.File({ level: 'info', filename: 'client-logs.log',
+ 6 other calls in file
6 7 8 9 10 11 12 13 14 15 16
const async = require("async"); const _ = require("underscore"); //mine var config = require("../config"); const logger = new winston.Logger(config.logger.winston); const db = require("../models"); const common = require("../common"); const pub_shared = require("./pub_shared"); const rename_underscores_to_dashes = pub_shared.rename_underscores_to_dashes;
+ 2 other calls in file
How does winston.Logger work?
winston.Logger is a constructor function in the winston logging library for Node.js that creates a new instance of a logger, which can be used to log messages to various transports (such as the console, file, or a remote server) with various logging levels and formatting options. When you create a new logger instance with new winston.Logger(options), you can specify options such as the transports to use, the log level threshold, and the format of the log messages. Once you have a logger instance, you can use its methods (log, info, warn, error, etc.) to log messages with various levels and data.
GitHub: OpenAgenda/oa-public
55 56 57 58 59 60 61 62 63 64 65 66
function getLogger(options = {}) { const callerFile = options.$callerFile || getCallerFile(2); const callerModule = options.$callerModule || getModule(path.resolve(callerFile)); const logger = new winston.Logger({ transports: getTransporters( _.merge({}, options, loggerConfigs.get(callerModule)) ) });
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const winston = require("winston"); const logger = winston.createLogger({ level: "info", format: winston.format.json(), transports: [ new winston.transports.Console(), new winston.transports.File({ filename: "error.log", level: "error" }), new winston.transports.File({ filename: "combined.log" }), ], }); logger.info("Hello, world!"); logger.error("Oops, something went wrong!");
This creates a logger that will output log messages with a level of info or higher to both the console and a file named combined.log. Messages with a level of error or higher will also be logged to a separate file named error.log.
winston.format is the most popular function in winston (1147 examples)