本文整理汇总了TypeScript中winston.createLogger函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createLogger函数的具体用法?TypeScript createLogger怎么用?TypeScript createLogger使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createLogger函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor() {
const alignedWithColorsAndTime = winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
//winston.format.align(),
winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`),
);
this.textLogger = winston.createLogger({
format: alignedWithColorsAndTime,
transports: [],
level: config.vpdb.logging.level,
});
if (config.vpdb.logging.console.enabled) {
this.textLogger.add(new winston.transports.Console());
}
/* istanbul ignore next */
if (config.vpdb.logging.file.text) {
const logPath = resolve(config.vpdb.logging.file.text);
const transport = new DailyRotateFile({
filename: basename(logPath),
dirname: dirname(logPath),
zippedArchive: true,
datePattern: 'YYYY-MM',
});
transport.on('rotate', (oldFilename, newFilename) => {
this.info(null, '[app] Rotating text logs from %s to %s.', oldFilename, newFilename);
});
transport.on('new', newFilename => {
this.info(null, '[app] Creating new text log at %s.', newFilename);
});
this.textLogger.add(transport);
this.info(null, '[app] Text logger enabled at %s.', logPath);
}
/* istanbul ignore next */
if (config.vpdb.logging.file.json) {
const logPath = resolve(config.vpdb.logging.file.json);
const transport = new DailyRotateFile({
filename: basename(logPath),
dirname: dirname(logPath),
zippedArchive: true,
datePattern: 'YYYY-MM',
});
transport.on('rotate', (oldFilename, newFilename) => {
this.info(null, '[app] Rotating JSON logs from %s to %s.', oldFilename, newFilename);
});
transport.on('new', newFilename => {
this.info(null, '[app] Creating new JSON log at %s.', newFilename);
});
this.jsonLogger = winston.createLogger({
format: winston.format.json(),
transports: [transport],
level: config.vpdb.logging.level,
});
this.info(null, '[app] JSON logger enabled at %s.', logPath);
}
}
示例2: createLogger
public static createLogger(
gatsbyEnv: GatsbyEnv = GatsbyEnv.Development,
): Logger {
const logger = winston.createLogger({
format: winston.format.json(),
level: 'info',
transports: [
// ==================================================================
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
// =================================================================
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
})
// =====================================================================
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
// =====================================================================
if (gatsbyEnv !== GatsbyEnv.Production) {
logger.add(
new winston.transports.Console({
format: winston.format.simple(),
}),
)
}
return logger
}
示例3: constructor
constructor () {
this.logger = winston.createLogger({
level: 'error',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
示例4: default
export default ({ config }: { config: LoggerConfig }): Logger => {
const myFormat = printf(info => {
return `${info.timestamp} ${info.level}: ${info.message}`;
});
const logger = createLogger({
level: config.level,
format: combine(timestamp(), myFormat),
transports: [new transports.Console({ format: format.simple() })],
});
return logger;
};
示例5: function
/**
* Configure logger
* @param {string} logfile Path to logfile
* @param {object} config Configuration for transports
* @return {winston.Logger}
*/
export default function(app: Application, options: ILoggingOptions) {
const cwd = process.cwd();
const logFile = path.resolve(cwd, `${options.dir}/${options.file}`);
const addRequestId = require("express-request-id")({ setHeader: false });
app.use(addRequestId);
morgan.token("id", (req: IRequestWithId) => req.id.split("-")[0]);
app.use(morgan("[:date[iso] #:id] Started :method :url for :remote-addr", {immediate: true}));
app.use(morgan("[: date[iso] #: id] Completed : status : res[content - length] in : response - time ms"));
// If logs directory does not exist, create one
if (!fs.existsSync(path.resolve(cwd, options.dir))) {
mkdirp.sync(path.resolve(cwd, options.dir));
}
// If log file does not exist, create one with empty content.
if (!fs.existsSync(logFile)) {
fs.writeFileSync(logFile, "");
}
const logger = winston.createLogger({
exitOnError: false,
format: winston.format.json(),
level: "info",
transports: [
new winston.transports.File({
filename: logFile,
handleExceptions: true,
level: "info",
maxFiles: 5,
maxsize: 5242880, // 5MB
}),
new winston.transports.Console({
handleExceptions: true,
level: "debug",
}),
],
});
return logger;
}
示例6: function
module.exports = async function (arg : any) {
let format;
if (arg && arg.quiet) {
transport = {
info : function () { return false },
warn : function () { return false },
error : function () { return false }
}
} else {
if (arg && arg.label) {
format = combine(
label({ label : arg.label }),
//timestamp(),
colorize(),
simple()
);
} else {
format = combine(
//timestamp(),
colorize(),
simple()
);
}
transport = createLogger({
transports: [
new (transports.Console)({
format
}),
new (transports.File)({
filename: await logFile(),
format : combine(
label({ label : arg.label }),
//timestamp(),
json()
)
})
]
})
}
return transport
}
示例7: constructor
/**
* Constructs a new instance of PolymerLogger. This creates a new internal
* `winston` logger, which is what we use to handle most of our logging logic.
*
* Should generally called with getLogger() instead of calling directly.
*/
constructor(options: Options) {
options = Object.assign({colorize: true}, options);
const formats = [];
if (options.colorize) {
formats.push(winston.format.colorize());
}
formats.push(winston.format.align());
formats.push(plylogPrettify({ colorize: options.colorize }));
this._transport = defaultConfig.transportFactory({
level: options.level || 'info',
format: winston.format.combine(...formats),
});
this._logger = winston.createLogger({transports: [this._transport]});
this.error = this._log.bind(this, 'error');
this.warn = this._log.bind(this, 'warn');
this.info = this._log.bind(this, 'info');
this.debug = this._log.bind(this, 'debug');
}
示例8:
import * as winston from 'winston';
const logger = winston.createLogger({
level: 'info',
transports: [new winston.transports.Console()],
});
export default logger;
示例9: new
import winston from "winston";
const logger = winston.createLogger({
transports: [
new (winston.transports.Console)({level: process.env.NODE_ENV === "production" ? "error" : "debug"}),
new (winston.transports.File)({filename: "debug.log", level: "debug"})
]
});
if (process.env.NODE_ENV !== "production") {
logger.debug("Logging initialized at debug level");
}
export default logger;
示例10: constructor
constructor (config: LoggerConfigInterface) {
this.adapter = winston.createLogger(config);
}