当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript format.printf方法代码示例

本文整理汇总了TypeScript中winston.format.printf方法的典型用法代码示例。如果您正苦于以下问题:TypeScript format.printf方法的具体用法?TypeScript format.printf怎么用?TypeScript format.printf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在winston.format的用法示例。


在下文中一共展示了format.printf方法的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: Rollbar

    // logger.add(new Loggly(logglyOptions));
    logger.add(new Rollbar({ rollbarConfig: rollbarOptions }));
} else {
    // development
    const formatterFunc = require("./winston-console.formatter").formatterFunc;

    // Ignore log messages if they have { private: true }
    const ignorePrivate = format((info, opts) => {
        if (info.private) {
            return false;
        }
        return info;
    });

    const myFormat = format.printf(info => {
        return `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`;
    });

    const consoleOptions = {
        level: LogLevel.DEBUG, // catches all messages
        // formatter: formatterFunc,
        // format: format.json(),
        // format: format.combine(ignorePrivate(), format.simple()),
        // format: format.combine(format.label({ label: "right meow!" }), format.timestamp(), myFormat),
    };
    // console.log("status1234:  + status" + formatterFunc);
    logger.add(new transports.Console(consoleOptions));
}

export default logger;
开发者ID:lmaran,项目名称:scoala21,代码行数:30,代码来源:logger.ts

示例3: getTimestamp

    if (hasFlag('color')) {
        return colors.gray(str)
    }

    if (supportsColor()) {
        return colors.gray(str)
    }

    return str
}
function getTimestamp () {
    return '[' + addColor(timestamp('HH:mm:ss')) + ']'
}
// create winston logger format
const logFmt = winston.format.printf((info) => {
    return `${getTimestamp()} ${info.level}: ${info.message}`
})

class Log {
    logger: Logger;
    constructor () {
        this.logger = winston.createLogger({
            level: 'error',
            transports: [new winston.transports.Console()],
            format: winston.format.combine(
                winston.format.colorize({ all: true }),
                logFmt
            )
        })
    }
    setVerbosity (v: LoggerOptions["level"]) {
开发者ID:0mkara,项目名称:remix,代码行数:31,代码来源:logger.ts

示例4: createLogger

import { configure, format, transports } from 'winston';

const { combine, timestamp, splat } = format;

const myFormat = format.printf(info => {
  return `${info.timestamp} ${info.level.toUpperCase()}: ${info.message}`;
});

export interface LoggerOptions {
  readonly logType: string;
  readonly logFile: string;
  readonly logLevel: string;
}

export function createLogger(options: LoggerOptions): void {
  const { logType, logLevel } = options;

  configure({
    exitOnError: false,
    format: combine(
      timestamp({
        format: 'YYYY-MM-DD HH:mm:ss'
      }),
      splat(),
      myFormat
    ),
    level: logLevel,
    transports:
      logType === 'file'
        ? [
            new transports.File({
开发者ID:mshick,项目名称:arrivals-osx,代码行数:31,代码来源:logger.ts

示例5:

      filename: magic8bot.loggerFile,
      datePattern: 'YYYY-MM-DD-HH',
      maxSize: '20m',
      maxFiles: '7d',
    })
  }

  if (process.env.NODE_ENV === 'development' || !fileLogger) {
    yield new winston.transports.Console({
      format: formatter,
    })
  }
}

const textFormat = winston.format.printf((info) => {
  return `${info.timestamp} [${info.level.padStart(5, ' ')}]: ${info.message}`
})

// prettier-ignore
const formatter = winston.format.combine(
    winston.format.timestamp(),
    winston.format.splat(),
    winston.format.simple(),
    textFormat
)

const isFileLoggerAvailable = () => {
  return magic8bot.loggerFile && magic8bot.loggerFile.length > 0
}

export const logger = winston.createLogger({
开发者ID:magic8bot,项目名称:magic8bot,代码行数:31,代码来源:logger.ts

示例6: keysExcluder

// Use object for better performances (~ O(1))
const excludedKeys = {
  level: true,
  message: true,
  splat: true,
  timestamp: true,
  label: true
}
function keysExcluder (key, value) {
  return excludedKeys[key] === true ? undefined : value
}

const consoleLoggerFormat = winston.format.printf(info => {
  let additionalInfos = JSON.stringify(info, keysExcluder, 2)
  if (additionalInfos === '{}') additionalInfos = ''
  else additionalInfos = ' ' + additionalInfos

  if (info.message && info.message.stack !== undefined) info.message = info.message.stack
  return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
})

const jsonLoggerFormat = winston.format.printf(info => {
  if (info.message && info.message.stack !== undefined) info.message = info.message.stack

  return JSON.stringify(info)
})

const timestampFormatter = winston.format.timestamp({
  format: 'YYYY-MM-DD HH:mm:ss.SSS'
})
const labelFormatter = winston.format.label({
  label
开发者ID:quoidautre,项目名称:PeerTube,代码行数:32,代码来源:logger.ts

示例7: logError

    format: winston.format.json(),
    transports: [
        new winston.transports.File({filename: "error.log", level: "error"})
    ]
});

const info_logger: winston.Logger = winston.createLogger({
    level: "info",
    format: winston.format.simple(),
    transports: []
});

if (process.env.NODE_ENV !== "production") {
    err_logger.add(new winston.transports.Console({
      format: winston.format.json()
    }));
}

if (process.env.NODE_ENV !== "production") {
    info_logger.add(new winston.transports.Console({
      format: winston.format.printf(info => `${info.message}`)
    }));
}

export function logError(source: string, error: any): void {
    err_logger.log("error", source, error);
}

export function logInfo(info: string): void {
    info_logger.log("info", info);
}
开发者ID:bradbesserman,项目名称:Crypto-Price-API,代码行数:31,代码来源:logger.ts

示例8:

        host?: string
        port?: number
        timeout?: number
        tag?: string
    },
    format?: {
        timestamp?: boolean,
        json?: boolean,
        colorize?: boolean
    },
    cwd?: string
    logDirectory?: string
}
// default format for Console, error at winston: if not json is specified is not logging in console
const loggerFormat = format.printf(({level, message }) => {
    return `${level}: ${message}`;
});
export const Logger = (options: LoggerOptions) => {

    options = _.defaultsDeep(options || {}, {
        fluentD: {},
        logDirectory: null,
        format: {
            timestamp: true,
            json: false,
            colorize: false
        },
        cwd: process.cwd()
    });

    // Defining custom formats 
开发者ID:LabShare,项目名称:lsc,代码行数:31,代码来源:logger.ts

示例9: keysExcluder

  splat: true,
  timestamp: true,
  label: true
}
function keysExcluder (key, value) {
  if (excludedKeys[key] === true) return undefined

  if (key === 'err') return value.stack

  return value
}

const consoleLoggerFormat = winston.format.printf(info => {
  let additionalInfos = JSON.stringify(info, keysExcluder, 2)
  if (additionalInfos === '{}') additionalInfos = ''
  else additionalInfos = ' ' + additionalInfos

  if (info.message && info.message.stack !== undefined) info.message = info.message.stack
  return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
})

const jsonLoggerFormat = winston.format.printf(infoArg => {
  let info = infoArg.err
    ? Object.assign({}, infoArg, { err: infoArg.err.stack })
    : infoArg

  if (infoArg.message && infoArg.message.stack !== undefined) {
    info = Object.assign({}, info, { message: infoArg.message.stack })
  }

  return JSON.stringify(info)
})
开发者ID:jiang263,项目名称:PeerTube,代码行数:32,代码来源:logger.ts

示例10: moment

import { createLogger, transports, format } from 'winston';
import moment from 'moment';

const timestamp = () => moment().format('YYYY-MM-DD HH:mm:ss.SSSS');
const rid = () => process.storage && process.storage.get('rid') ? `[${process.storage.get('rid')}]` : '';

const customFormat = format.printf(options =>
  `${timestamp()} ${options.level.toUpperCase()} ${rid()}
  ${(options.message ? options.message : '')}
  ${(options.meta && Object.keys(options.meta).length
    ? '\n\t' + JSON.stringify(options.meta) // tslint:disable-line:prefer-template
    : '')}`);

const logger = createLogger({
  level: process.env.LOG_LEVEL || 'info',
  format: customFormat,
  transports: [
    new (transports.Console)(),
  ],
});

export default logger;
开发者ID:Alexandr-Baluhin,项目名称:nodejs-graphql-template,代码行数:22,代码来源:logger.ts


注:本文中的winston.format.printf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。