本文整理汇总了TypeScript中winston.add函数的典型用法代码示例。如果您正苦于以下问题:TypeScript add函数的具体用法?TypeScript add怎么用?TypeScript add使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(type:string, params?: { name:string, test?: boolean, external?:boolean, network?:{ discover: any, ports: any, network:any }}){
this.type = type;
this.id = params.name;
if (params !== undefined && params.test !== undefined) this.test = params.test
else this.test = false
if (params !== undefined && params.external !== undefined) this.external = params.external
else this.external = false
if (!this.test) {
try {
winston.add(winston.transports.File, { filename: `./logs/${type}-${this.id}.log` , level:'info'});
/*winston.add(require('winston-graylog2'), {
name: 'Graylog',
level: 'warning',
silent: false,
handleExceptions: false,
graylog: {
servers: [{host: '127.0.0.1', port: 12201}],
hostname: this.id,
facility: "leader",
bufferSize: 1400
}
});*/
} catch (e){ }
if (params !== undefined && params.network !== undefined)
winston.info(type +" %s started in port %s ",this.id, params.network.ports.port);
}
if (params !== undefined && !this.test && params.network !== undefined) this.startNetwork(params.network);
}
示例2: InitializeLogger
public static InitializeLogger() : void {
//initialize the winston logger with daily log rotates
let env : string = process.env.NODE_ENV || "development";
env = env.trim();
let logFilePath : string = path.join(__dirname, "../../logs");
//create the log file directory is it does not exist
if(!fs.existsSync(logFilePath)) {
fs.mkdirSync(logFilePath);
}
if(env == "development") {
Winston.add(winstonRotateFile, {
filename: path.join(logFilePath, "_info.log"),
datePattern: "yyyy-MM-dd",
prepend: true,
prettyPrint: true,
level: "info"
});
}
else {
Winston.add(winstonRotateFile, {
filename: path.join(logFilePath, "_error.log"),
datePattern: "yyyy-MM-dd",
prepend: true,
prettyPrint: true,
level: "warn"
});
//remove console output in production
Winston.remove(Winston.transports.Console);
}
Winston.handleExceptions(new winstonRotateFile({
filename: path.join(logFilePath, "_exceptions.log"),
datePattern: "yyyy-MM-dd",
prepend: true,
prettyPrint: true
}));
}
示例3:
import * as winston from 'winston';
// set up the logger with a transport
const _logger = winston.add(new winston.transports.Console({
format: (winston as any).format.simple(),
}));
export const logger = _logger;
示例4: express
const app = express();
const ROOT = path.join(path.resolve(''));
/*
* Configure Winston
*/
winston.addColors({
debug: 'green',
info: 'cyan',
silly: 'magenta',
warn: 'yellow',
error: 'red'
});
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
level: process.env.LOG_LEVEL,
colorize: true
});
/*
* Connect to database
* Info: See database.ts to configure settings
*/
import { ConnectToDatabase } from './database';
ConnectToDatabase();
/*
* Configure Express.js rendering engine
*/
示例5: parseFloat
var narrative : string = values[3];
var amount : number = parseFloat(values[4]);
if (isNaN(amount)) {
var errorMsg = "while parsing: '" + values[4] + "' is not a number. Line is ignored";
winston.log("error", errorMsg);
return null; // skip line
}
return new Transaction(date, origin, to, narrative, amount);
}
var transactionDict : Transaction[] = new Array();
var personDict = {};
winston.level = "debug"
winston.add(winston.transports.File, { filename: 'logFiles/log.txt' });
//winston.remove(winston.transports.Console);
loadCSV("res/DodgyTransactions2015.csv");
var stdin = process.stdin;
stdin.addListener("data", function(data) {
var answer = data.toString().trim();
if (answer === "listAll") listAll()
else if (answer.startsWith("listTransactions")) {
var args = answer.split(" ");
listTransactions(args[1] + " " + args[2]);
} else if (answer === "q" || answer === "quit") {
throw new Error("");
示例6: Promise
import fs from 'fs';
import http from 'http';
import path from 'path';
import util from 'util';
import winston from 'winston';
import writeFileAtomic from 'write-file-atomic';
import app from '../src/app';
import GitHub from '../src/github';
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { timestamp: true });
const gh = new GitHub(process.env.GITHUB_TOKEN as string);
app.set('port', process.env.PORT || 3000);
const mkdir = util.promisify(fs.mkdir);
const dirExists = util.promisify(fs.exists);
const atomic = (file: string, data: any) => {
return new Promise((res, rej) => {
writeFileAtomic(file, JSON.stringify(data), err => (err ? rej(err) : res()));
});
};
async function updateShowcases() {
const dbPath = path.join(__dirname, '..', '.db');
const showcasePath = path.join(dbPath, 'showcase');
if (!await dirExists(dbPath)) {