Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b7e8c9a

Browse files
author
Michal Vlasák
committed
Refactor
1 parent f6decb1 commit b7e8c9a

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
5959
const messageKey = options.pretty ? 'msg' : 'message'; // "message" is the best option for Google Stackdriver,
6060
const streams = initLoggerStreams(defaultLevel, Object.assign({}, options, { messageKey }));
6161

62-
if (!options.ignoredHttpMethods) {
63-
options.ignoredHttpMethods = ['OPTIONS'];
64-
}
62+
options.ignoredHttpMethods = options.ignoredHttpMethods || ['OPTIONS'];
6563

6664
const logger = (pino(
6765
// no deep-merging needed, so assign is OK
@@ -77,8 +75,6 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
7775
),
7876
(pinoms as any).multistream(streams)
7977
) as PinoLogger) as AckeeLogger;
80-
logger.warning = logger.warn;
81-
logger.options = options;
8278

8379
// Add maxLevel support to pino-multi-stream
8480
// This could be replaced with custom pass-through stream being passed to multistream, which would filter the messages
@@ -87,10 +83,12 @@ const defaultLogger = (options: AckeeLoggerOptions & { loggerName?: string } = {
8783
streamMaxLevelWrite(chunk);
8884
return true;
8985
};
90-
logger.express = expressMiddleware.bind(logger);
91-
logger.expressError = expressErrorMiddleware as any;
92-
93-
return logger;
86+
return Object.assign(logger, {
87+
options,
88+
express: expressMiddleware.bind(logger),
89+
expressError: expressErrorMiddleware as any,
90+
warning: logger.warn,
91+
});
9492
};
9593

9694
let rootLogger: AckeeLogger;

src/streams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import * as pino from 'pino';
4-
import { Transform } from 'stream';
4+
import { Transform, TransformCallback } from 'stream';
55
import { AckeeLoggerOptions, AckeeLoggerStream } from './interfaces';
66
import { levels } from './levels';
77
import { StackDriverFormatStream } from './stackdriver';
@@ -13,7 +13,7 @@ const pkgJson = JSON.parse(fs.readFileSync(path.resolve(path.join(__dirname, '..
1313
const getDefaultTransformStream = (options: AckeeLoggerOptions & { messageKey: string; loggerName?: string }) => {
1414
class DefaultTransformStream extends Transform {
1515
// tslint:disable-next-line:function-name
16-
public _transform(chunk: any, _encoding: string, callback: (error?: Error | undefined, data?: any) => void) {
16+
public _transform(chunk: any, _encoding: string, callback: TransformCallback) {
1717
const obj = JSON.parse(chunk);
1818
obj.pkgVersion = pkgJson.version;
1919
const loggerName = options.loggerName;

0 commit comments

Comments
 (0)