本文整理汇总了TypeScript中winston.format.simple方法的典型用法代码示例。如果您正苦于以下问题:TypeScript format.simple方法的具体用法?TypeScript format.simple怎么用?TypeScript format.simple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类winston.format
的用法示例。
在下文中一共展示了format.simple方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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
}
示例2: getConfig
export function getConfig() {
const configPath = process.env.CONFIG_PATH || process.argv[2] || './config.json'
let config: Config
try {
config = { ...configDefaults, ...JSON.parse(fs.readFileSync(configPath).toString()) }
} catch (e) {
console.error(`Failed to read config: ${e}`)
config = { ...configDefaults }
}
if (process.env['GAIA_DISK_STORAGE_ROOT_DIR']) {
config.diskSettings.storageRootDirectory = process.env['GAIA_DISK_STORAGE_ROOT_DIR']
}
const formats = [
config.argsTransport.colorize ? winston.format.colorize() : null,
config.argsTransport.timestamp ?
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }) : null,
config.argsTransport.json ? winston.format.json() : winston.format.simple()
].filter(f => f !== null)
const format = formats.length ? winston.format.combine(...formats) : null
logger.configure({
format: format,
transports: [new winston.transports.Console(config.argsTransport)]
})
return config
}
示例3: getConfig
export function getConfig() {
const configPath = process.env.CONFIG_PATH || process.argv[2] || './config.json'
let config: Config
try {
config = Object.assign(
{}, configDefaults, JSON.parse(fs.readFileSync(configPath).toString()))
} catch (e) {
console.error(`Error reading config "${configPath}": ${e}`)
config = Object.assign({}, configDefaults)
}
const formats = [
config.argsTransport.colorize ? winston.format.colorize() : null,
config.argsTransport.timestamp ?
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }) : null,
config.argsTransport.json ? winston.format.json() : winston.format.simple()
].filter(f => f !== null)
const format = formats.length ? winston.format.combine(...formats) : null
logger.configure({
format: format,
transports: [new winston.transports.Console(config.argsTransport)]
})
return config
}
示例4: constructor
constructor(browser: string, headlessMode: boolean = false, logger?: winston.Logger) {
if(logger){
this.logger =logger;
}else {
this.logger = winston.loggers.get('tasteeLog');
this.logger.configure({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.simple()
),
transports: [
new winston.transports.Console()
]
});
}
if (browser) {
let webdriver = require('selenium-webdriver');
switch (browser) {
case 'chrome':
if (headlessMode) {
var chrome = require('selenium-webdriver/chrome');
this.driver = new webdriver.Builder()
.withCapabilities(selenium.Capabilities.chrome())
.setChromeOptions(new chrome.Options().headless())
.build();
}
else {
this.driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
}
break;
case 'firefox':
if (headlessMode) {
var firefox = require('selenium-webdriver/firefox');
this.driver = new webdriver.Builder()
.withCapabilities(selenium.Capabilities.firefox())
.setFirefoxOptions(new firefox.Options().headless())
.build();
}
else {
this.driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
}
break;
default:
this.driver = new webdriver.Builder()
.forBrowser('phantomjs')
.build();
break;
}
}
this.reporter = new TasteeReporter();
}
示例5: 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;
};
示例6:
import * as winston from 'winston';
/**
* A default logger for the app
*/
export const logger = winston.createLogger({
format: winston.format.json(),
level: 'info',
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.Console({
format: winston.format.simple(),
}),
],
});
示例7: stream
handleExceptions: false,
maxsize: (1 * 1024 * 1024), // 1MB
maxFiles: 5,
format: format.combine(
format.splat(),
format.timestamp(),
format.json()
)
}),
new transports.Console({
level: 'debug',
silent: process.env.NODE_ENV === 'test',
handleExceptions: true,
format: format.combine(
format.colorize(),
format.simple()
)
})
],
exitOnError: false
});
/**
* This is the options object we relay to `morgan`
*/
export function stream(logDirectory): StreamOptions {
return require('rotating-file-stream')('access.log', {
interval: '7d', // rotate weekly
path: logDirectory
});
};
示例8:
import winston from 'winston';
export const logger = {
level: 'error',
exitOnError: false,
transports: [ new winston.transports.Console({ format: winston.format.simple() }) ],
};
示例9: describe
describe('Tastee Engine', function () {
let engine: TasteeEngine;
logger.configure({
level: 'debug',
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.simple()
),
transports: [
new winston.transports.Console()
]
});
beforeEach(function () {
engine = new TasteeEngine(null);
let driver = jasmine.createSpyObj("driver", ["quit"]);
engine.driver = driver;
});
it(" propagates logger", function () {
const infoLog = winston.loggers.get('infoLog');
infoLog.configure({
level: 'info'
});
let engineInfo = new TasteeEngine(null, false, infoLog);
expect(engineInfo.logger).toBe(infoLog);
});
it(" quits selenium driver properly", function () {
engine.stop();
expect(engine.driver.quit).toHaveBeenCalled();
});
it(" execute simple js code", (done) => {
let instruction = new Instruction(1, 'a line', '1+1');
let promise = engine.execute([instruction]);
promise.then(result => {
expect(result.length).toBe(1);
expect(result[0].valid).toBe(true);
done();
});
});
it(" execute empty codeLines", (done) => {
let instruction = new Instruction(1, 'a line', '');
engine.execute([instruction]).then(result => {
expect(result.length).toBe(1);
expect(result[0].valid).toBe(true);
done();
});
});
it(" execute unknown instruction", (done) => {
let instruction = new Instruction(1, 'a line', 'bad code line');
engine.execute([instruction]).then(result => {
expect(result.length).toBe(1);
expect(result[0].valid).toBe(false);
done();
});
});
it(" execute promise error", (done) => {
let instruction = new Instruction(1, 'a line', 'throw new Error("exception!");');
engine.execute([instruction]).then(result => {
expect(result.length).toBe(1);
expect(result[0].valid).toBe(false);
done();
});
});
});