本文整理汇总了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);
}
}
开发者ID:freezy,项目名称:node-vpdb,代码行数:58,代码来源:logger.ts
示例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
}
开发者ID:jessestuart,项目名称:jessestuart.com,代码行数:29,代码来源:log.ts
示例3: constructor
constructor () {
this.logger = winston.createLogger({
level: 'error',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
开发者ID:0mkara,项目名称:remix,代码行数:10,代码来源:logger.ts
示例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;
};
开发者ID:sebelga,项目名称:blog-app-googlecloud,代码行数:13,代码来源:logger.ts
示例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;
}
开发者ID:charlesponti,项目名称:cthulhu,代码行数:50,代码来源:logger.ts
示例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
}
开发者ID:sixteenmillimeter,项目名称:mcopy,代码行数:41,代码来源:index.ts
示例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');
}
开发者ID:Polymer,项目名称:plylog,代码行数:27,代码来源:index.ts
示例8:
import * as winston from 'winston';
const logger = winston.createLogger({
level: 'info',
transports: [new winston.transports.Console()],
});
export default logger;
开发者ID:ericmasiello,项目名称:synbydesign,代码行数:8,代码来源:logger.ts
示例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;
开发者ID:paul-phan,项目名称:TypeScript-Node-Starter,代码行数:14,代码来源:logger.ts
示例10: constructor
constructor (config: LoggerConfigInterface) {
this.adapter = winston.createLogger(config);
}
开发者ID:RWOverdijk,项目名称:stix,代码行数:3,代码来源:LoggerService.ts
注:本文中的winston.createLogger函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论