|
1 | 1 | [](https://circleci.com/gh/voiceflow/logger)
|
2 | 2 | [](https://sonarcloud.io/dashboard?id=voiceflow_logger)
|
3 | 3 | [](https://sonarcloud.io/dashboard?id=voiceflow_logger)
|
4 |
| -# logger |
5 |
| - |
6 |
| -Author: Frank Gu < <[email protected]>> |
7 |
| -Date: Dec 11, 2019 |
8 | 4 |
|
9 |
| -A logging package for VERY fast and useful JSON logging. |
| 5 | +# logger |
10 | 6 |
|
11 |
| -- All log entries go to `process.stdout` |
12 |
| -- Minimal overhead and no logger hierarchies |
13 |
| -- Multiple instantiations allowed |
| 7 | +A standardized package for logging built on `pino`. |
14 | 8 |
|
15 | 9 | ## Usage
|
16 | 10 |
|
17 |
| -```javascript |
18 |
| -const Logger = require('@voiceflow/logger').default; |
19 |
| -// or |
20 |
| -import Logger from '@voiceflow/logger'; |
21 |
| - |
22 |
| -const defaultOptions = { |
23 |
| - level: 'info', |
24 |
| - pretty: false, |
25 |
| -}; |
26 |
| - |
27 |
| -const overrideOptions = { |
28 |
| - level: 'trace', // Minimum log-level to be printed |
29 |
| - pretty: true, // Pretty print |
30 |
| -}; |
31 |
| - |
32 |
| -const defaultLogger = new Logger(); // Default options |
33 |
| -const customLogger = new Logger(overrideOptions); |
34 |
| - |
35 |
| -defaultLogger.trace('this is a trace'); |
36 |
| -defaultLogger.debug('this is a debug'); |
37 |
| -defaultLogger.info('this is an info'); |
38 |
| -defaultLogger.warn('this is a warning'); |
39 |
| -defaultLogger.error('this is an error'); |
40 |
| -defaultLogger.fatal('this is a fatal'); |
41 |
| - |
42 |
| -customLogger.trace('this is a trace'); |
43 |
| -customLogger.debug('this is a debug'); |
44 |
| -customLogger.info('this is an info'); |
45 |
| -customLogger.warn('this is a warning'); |
46 |
| -customLogger.error('this is an error'); |
47 |
| -customLogger.fatal('this is a fatal'); |
48 |
| -``` |
| 11 | +```ts |
| 12 | +import { createLogger, LogLevel, LogFormat } from '@voiceflow/logger'; |
49 | 13 |
|
50 |
| -### Development Assitance |
| 14 | +const logger = createLogger({ format: LogFormat.JSON, level: LogLevel.INFO }); |
51 | 15 |
|
52 |
| -- For `warn` logs, the calling function and line number is included |
53 |
| -- For `error` and `fatal` logs, the full call-stack is included |
| 16 | +const inlineLogger = createLogger({ format: LogFormat.INLINE, level: LogLevel.WARN }); |
54 | 17 |
|
55 |
| -### Pretty Printing |
| 18 | +const detailedLogger = createLogger({ format: LogFormat.DETAILED, level: LogLevel.TRACE }); |
56 | 19 |
|
57 |
| -Pretty printing will add colors, parse unix epoch timestamps into UTC time. |
| 20 | +logger.trace('this is a trace log'); |
| 21 | +logger.debug('this is a debug log'); |
| 22 | +logger.info('this is an info log'); |
| 23 | +logger.warn('this is a warning log'); |
| 24 | +logger.error('this is an error log'); |
| 25 | +logger.fatal('this is a fatal log'); |
| 26 | +``` |
0 commit comments