本文整理汇总了TypeScript中pino类的典型用法代码示例。如果您正苦于以下问题:TypeScript pino类的具体用法?TypeScript pino怎么用?TypeScript pino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pino类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: logger
"use strict";
import * as logger from "pino";
export default logger();
示例2: pino
import { Server } from 'hapi';
import * as pino from 'pino';
import * as HapiPino from 'hapi-pino';
const pinoLogger = pino();
const server = new Server();
server.register({
plugin: HapiPino,
options: {
logPayload: false,
logRouteTags: false,
stream: process.stdout,
prettyPrint: process.env.NODE_ENV !== 'PRODUCTION',
levelTags: {
trace: 'trace',
debug: 'debug',
info: 'info',
warn: 'warn',
error: 'error'
},
allTags: 'info',
serializers: {
req: (req: any) => console.log(req)
},
instance: pinoLogger,
logEvents: false,
mergeHapiLogData: false,
ignorePaths: ['/testRoute'],
level: 'debug',
示例3: pinoms
import * as fs from 'fs';
import * as pino from 'pino';
import * as pinoms from 'pino-multi-stream';
const streams: pinoms.Streams = [
{ stream: process.stdout }, // an "info" level destination stream
{ level: 'error', stream: process.stderr }, // an "error" level destination stream
{ stream: fs.createWriteStream('/tmp/info.stream.out') },
{ level: 'fatal', stream: fs.createWriteStream('/tmp/fatal.stream.out') }
];
const logger = pinoms({
level: 'warn',
streams
});
const log = pino({
level: 'debug' // this MUST be set at the lowest level of the
// destinations
}, pinoms.multistream(streams));
示例4: pino
import * as _ from 'lodash';
import * as pino from 'pino';
import * as util from 'util';
export const options = { enabled: process.env.NODE_ENV === 'test' ? false : true };
export interface Logger {
debug: (s: string, ...args: any[]) => void;
info: (s: string, ...args: any[]) => void;
warn: (s: string, ...args: any[]) => void;
error: (s: string, ...args: any[]) => void;
}
const logger = pino({ level: 'debug' });
const cache = new Map();
export function getLogger(name: string): Logger {
if (!options.enabled) {
return new Proxy({}, { get: () => _.noop }) as Logger;
}
const label = _.trimEnd(name, 'Impl');
if (cache.has(label)) {
return cache.get(label);
}
const childLogger = logger.child({ label });
const wrappedLogger = {
debug: (s: string, ...args) => childLogger.debug(util.format(s, ...args)),
info: (s: string, ...args) => childLogger.info(util.format(s, ...args)),
warn: (s: string, ...args) => childLogger.warn(util.format(s, ...args)),
error: (s: string, ...args) => childLogger.error(util.format(s, ...args))
};
示例5: Pino
import * as Pino from 'pino'
import Server from './server'
import Config from './config'
const pino = Pino({
prettyPrint: ['dev', 'test'].indexOf(Config.node_env) > -1,
level: Config.node_env === 'test' ? 'error' : 'info',
})
function warnEnvironment(vars: string[]) {
const missing = vars.filter((val) => process.env[val] === undefined)
missing.forEach((name) => pino.warn(`Environment variable ${name} is not set`))
}
warnEnvironment([
'HACKBOT_PASSWORD',
'ADMIN_USERNAME',
'ADMIN_PASSWORD',
'PUSHER_URL',
'SLACK_API_TOKEN',
])
const server = new Server(pino)
server.start().then((info) => {
pino.info(`Server started on port ${info.Port}`)
if (process.send !== undefined) {
process.send('started')
}
}).catch((err) => {
pino.error('Server could not be started')
pino.error(err)
示例6: main
async function main() {
console.log('Running Po.et Node')
console.log('')
console.log('Loading Configuration...')
const configuration = loadConfigurationWithDefaults()
console.log('Switching to Structured Logging')
console.log('Logging Level:', configuration.loggingLevel)
console.log('')
const logger: Pino.Logger = Pino({
level: configuration.loggingLevel,
prettyPrint: configuration.loggingPretty,
})
logger.info(configuration, 'Loaded Configuration and merged with defaults')
const loggingConfiguration = {
loggingLevel: configuration.loggingLevel,
loggingPretty: configuration.loggingPretty,
}
const api = new API({
...loggingConfiguration,
port: configuration.apiPort,
dbUrl: configuration.mongodbUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
})
try {
await api.start()
} catch (exception) {
logger.error({ exception }, 'API was unable to start')
}
const view = new View({
...loggingConfiguration,
dbUrl: configuration.mongodbUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
})
try {
await view.start()
} catch (exception) {
logger.error({ exception }, 'View was unable to start')
}
const storage = new Storage({
...loggingConfiguration,
dbUrl: configuration.mongodbUrl,
ipfsUrl: configuration.ipfsUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
downloadIntervalInSeconds: configuration.downloadIntervalInSeconds,
downloadRetryDelayInMinutes: configuration.downloadRetryDelayInMinutes,
downloadMaxAttempts: configuration.downloadMaxAttempts,
downloadTimeoutInSeconds: configuration.downloadTimeoutInSeconds,
})
try {
await storage.start()
} catch (exception) {
logger.error({ exception }, 'Storage was unable to start')
}
if (configuration.enableTimestamping) {
const blockchainWriter = new BlockchainWriter({
...loggingConfiguration,
dbUrl: configuration.mongodbUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
insightUrl: configuration.insightUrl,
bitcoinAddress: configuration.bitcoinAddress,
bitcoinAddressPrivateKey: configuration.bitcoinAddressPrivateKey,
poetNetwork: configuration.poetNetwork,
poetVersion: configuration.poetVersion,
timestampIntervalInSeconds: configuration.timestampIntervalInSeconds,
})
try {
await blockchainWriter.start()
} catch (exception) {
logger.error({ exception }, 'BlockchainWriter was unable to start')
}
}
const blockchainReader = new BlockchainReader({
...loggingConfiguration,
dbUrl: configuration.mongodbUrl,
rabbitmqUrl: configuration.rabbitmqUrl,
insightUrl: configuration.insightUrl,
poetNetwork: configuration.poetNetwork,
poetVersion: configuration.poetVersion,
minimumBlockHeight: configuration.minimumBlockHeight,
forceBlockHeight: configuration.forceBlockHeight,
blockchainReaderIntervalInSeconds: configuration.blockchainReaderIntervalInSeconds,
})
try {
await blockchainReader.start()
} catch (exception) {
logger.error({ exception }, 'BlockchainReader was unable to start')
}
}
示例7: createModuleLogger
export function createModuleLogger(configuration: LoggingConfiguration, dirname: string): Pino.Logger {
return childWithModuleName(Pino(loggingConfigurationToPinoConfiguration(configuration)), dirname)
}