Skip to content

Commit 0f0b5d4

Browse files
committed
docs(logger): describe defaults
1 parent 70b9870 commit 0f0b5d4

6 files changed

Lines changed: 67 additions & 59 deletions
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LogTransport } from '@shiftcode/logger'
22

3+
import { ValueOrFactory } from '../helper/value-or-factory.type'
34
import { LoggerFeature } from '../logger-feature.type'
45
import { LoggerFeatureKind } from '../logger-feature-kind.enum'
56
import {
@@ -8,18 +9,15 @@ import {
89
BrowserConsoleLogTransportService,
910
} from './browser-console-log-transport.service'
1011

11-
export function withBrowserConsoleTransport(
12-
browserConsoleLogTransportConfigOrFactory:
13-
| BrowserConsoleLogTransportConfig
14-
| (() => BrowserConsoleLogTransportConfig),
15-
): LoggerFeature {
16-
const configProvider =
17-
typeof browserConsoleLogTransportConfigOrFactory === 'function'
18-
? { provide: BROWSER_CONSOLE_LOG_TRANSPORT_CONFIG, useFactory: browserConsoleLogTransportConfigOrFactory }
19-
: { provide: BROWSER_CONSOLE_LOG_TRANSPORT_CONFIG, useValue: browserConsoleLogTransportConfigOrFactory }
20-
12+
export function withBrowserConsoleTransport(config: ValueOrFactory<BrowserConsoleLogTransportConfig>): LoggerFeature {
2113
return {
2214
kind: LoggerFeatureKind.TRANSPORT,
23-
providers: [configProvider, { provide: LogTransport, useClass: BrowserConsoleLogTransportService, multi: true }],
15+
providers: [
16+
{
17+
provide: BROWSER_CONSOLE_LOG_TRANSPORT_CONFIG,
18+
...(typeof config === 'function' ? { useFactory: config } : { useValue: config }),
19+
},
20+
{ provide: LogTransport, useClass: BrowserConsoleLogTransportService, multi: true },
21+
],
2422
}
2523
}

libs/core/src/lib/logger/cloud-watch-log/cloud-watch-log-config.injection-token.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import { LogLevel } from '@shiftcode/logger'
33

44
export interface CloudWatchLogV2Config {
55
logLevel: LogLevel
6+
7+
/**
8+
* the url of the CloudWatchApi Construct from @shiftcode/cdk-utils
9+
*/
610
apiUrl: string
711

812
/** milliseconds until logs are flushed to aws */
913
flushInterval: number
14+
15+
/**
16+
* replacer function for JSON.stringify
17+
* @default {@link jsonMapSetStringifyReplacer}
18+
*/
1019
jsonStringifyReplacer?: (key: string, value: any) => any
1120

12-
/** max number of sub-threshold log events to buffer before dropping oldest. default 100 */
21+
/**
22+
* max number of sub-threshold log events to buffer before dropping oldest.
23+
* @default 100
24+
*/
1325
bufferSize?: number
1426
}
1527

libs/core/src/lib/logger/cloud-watch-log/cloud-watch-log-transport.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export class CloudWatchLogV2TransportService extends LogTransport {
1818
}
1919

2020
log(level: LogLevel, clazzName: string, _color: string, timestamp: Date, args: unknown[]): void {
21-
// checking the log level is done in the cloudWatchLogger. important.
21+
/**
22+
* checking the log level is done in the {@link CloudWatchLogV2Service} in order to do the buffering of below-level logs.
23+
*/
2224
this.cloudWatchLogger.addMessage(level, clazzName, timestamp, args)
2325
}
2426
}

libs/core/src/lib/logger/console-json/with-console-json-log-transport.function.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ import {
99
ConsoleJsonLogTransportService,
1010
} from './console-json-log-transport.service'
1111

12-
export function withConsoleJsonLogTransport(
13-
consoleJsonLogTransportConfig: ValueOrFactory<ConsoleJsonLogTransportConfig>,
14-
): LoggerFeature {
12+
export function withConsoleJsonLogTransport(config: ValueOrFactory<ConsoleJsonLogTransportConfig>): LoggerFeature {
1513
return {
1614
kind: LoggerFeatureKind.TRANSPORT,
1715
providers: [
1816
{
1917
provide: CONSOLE_JSON_LOG_TRANSPORT_CONFIG,
20-
...(typeof consoleJsonLogTransportConfig === 'function'
21-
? { useFactory: consoleJsonLogTransportConfig }
22-
: { useValue: consoleJsonLogTransportConfig }),
18+
...(typeof config === 'function' ? { useFactory: config } : { useValue: config }),
2319
},
2420
{ provide: LogTransport, useClass: ConsoleJsonLogTransportService, multi: true },
2521
],

libs/core/src/lib/logger/node-console/node-console-log-transport.service.ts

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,46 @@ export class NodeConsoleLogTransportService extends LogTransport {
4040

4141
log(level: LogLevel, clazzName: string, hexColor: string, timestamp: Date, args: any[]) {
4242
if (this.isLevelEnabled(level)) {
43-
const now = loggingTimeFormat.format(timestamp)
44-
// make sure to not alter the input args array
45-
if (typeof args[0] === 'string') {
46-
// if first arg is string, also colorize it
47-
args = [
48-
logLevelEmoji[level],
49-
colorizeForConsole(`${now} - ${clazzName} :: ${args[0]}`, hexColor),
50-
...args.slice(1).map(this.stringifyJson),
51-
]
52-
} else {
53-
args = [
54-
logLevelEmoji[level],
55-
colorizeForConsole(`${now} - ${clazzName} ::`, hexColor),
56-
...args.map(this.stringifyJson),
57-
]
58-
}
43+
return
44+
}
5945

60-
/* eslint-disable no-console */
61-
switch (level) {
62-
case LogLevel.DEBUG:
63-
console.debug(...args)
64-
break
65-
case LogLevel.ERROR:
66-
console.error(...args)
67-
break
68-
case LogLevel.INFO:
69-
console.info(...args)
70-
break
71-
case LogLevel.WARN:
72-
console.warn(...args)
73-
break
74-
case LogLevel.OFF:
75-
break
76-
default:
77-
return level // exhaustive check
78-
}
79-
/* eslint-enable no-console */
46+
const now = loggingTimeFormat.format(timestamp)
47+
// make sure to not alter the input args array
48+
if (typeof args[0] === 'string') {
49+
// if first arg is string, also colorize it
50+
args = [
51+
logLevelEmoji[level],
52+
colorizeForConsole(`${now} - ${clazzName} :: ${args[0]}`, hexColor),
53+
...args.slice(1).map(this.stringifyJson),
54+
]
55+
} else {
56+
args = [
57+
logLevelEmoji[level],
58+
colorizeForConsole(`${now} - ${clazzName} ::`, hexColor),
59+
...args.map(this.stringifyJson),
60+
]
61+
}
62+
63+
/* eslint-disable no-console */
64+
switch (level) {
65+
case LogLevel.DEBUG:
66+
console.debug(...args)
67+
break
68+
case LogLevel.ERROR:
69+
console.error(...args)
70+
break
71+
case LogLevel.INFO:
72+
console.info(...args)
73+
break
74+
case LogLevel.WARN:
75+
console.warn(...args)
76+
break
77+
case LogLevel.OFF:
78+
break
79+
default:
80+
return level // exhaustive check
8081
}
82+
/* eslint-enable no-console */
8183
}
8284

8385
private readonly stringifyJson = (data: unknown) => {

libs/core/src/lib/logger/node-console/with-node-console-transport.function.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import { LoggerFeature } from '../logger-feature.type'
55
import { LoggerFeatureKind } from '../logger-feature-kind.enum'
66
import { NODE_CONSOLE_LOG_TRANSPORT_CONFIG, NodeConsoleLogTransportService } from './node-console-log-transport.service'
77

8-
export function withNodeConsoleTransport(nodeConsoleLogTransportConfig: ValueOrFactory<any>): LoggerFeature {
8+
export function withNodeConsoleTransport(config: ValueOrFactory<any>): LoggerFeature {
99
return {
1010
kind: LoggerFeatureKind.TRANSPORT,
1111
providers: [
1212
{
1313
provide: NODE_CONSOLE_LOG_TRANSPORT_CONFIG,
14-
...(typeof nodeConsoleLogTransportConfig === 'function'
15-
? { useFactory: nodeConsoleLogTransportConfig }
16-
: { useValue: nodeConsoleLogTransportConfig }),
14+
...(typeof config === 'function' ? { useFactory: config } : { useValue: config }),
1715
},
1816
{ provide: LogTransport, useClass: NodeConsoleLogTransportService, multi: true },
1917
],

0 commit comments

Comments
 (0)