Skip to content

Commit 66a6730

Browse files
committed
fix(node): rename proc-log event-name
1 parent 91db610 commit 66a6730

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ framework of choice for logging. Check `initProcLog()` for inspiration.
546546
Emits the following process event:
547547

548548
```
549-
process.emit('log', level, name, fmt, args)
549+
process.emit('log-level', level, name, fmt, args)
550550
```
551551

552552
where

src/ProcLog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { inspectOpts, inspectNamespaces, INFO } from './utils.js'
99
* @typedef {LogOptions & {Log: typeof Log}} LogOptionsWithCustomLog
1010
*/
1111

12-
const EVENT = 'log'
12+
export const EVENT_NAME = 'log-level'
1313

1414
const defaultOptions = {
1515
level: INFO,
@@ -69,7 +69,7 @@ export class ProcLog extends LogBase {
6969

7070
_log(level, fmt, args) {
7171
// @ts-expect-error
72-
process.emit(EVENT, level, this.name, fmt, args)
72+
process.emit(EVENT_NAME, level, this.name, fmt, args)
7373
}
7474
}
7575

@@ -84,9 +84,9 @@ export function initProcLog(options) {
8484
logger[namespace] || (logger[namespace] = new LogCls(namespace, options))
8585

8686
// prevent multiple log-lines from adding more than one listener
87-
process.removeAllListeners(EVENT)
87+
process.removeAllListeners(EVENT_NAME)
8888
// listen on event
89-
process.on(EVENT, (level, namespace, fmt, args) => {
89+
process.on(EVENT_NAME, (level, namespace, fmt, args) => {
9090
const log = getLogger(namespace)
9191
log[level.toLowerCase()]?.(fmt, ...args)
9292
})

src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ import { LogEcs } from './ecs/LogEcs.js'
1212
import { logger } from './logger.js'
1313
import { browserLogs } from './browserLogs.js'
1414
import { httpLogs } from './httpLogs.js'
15-
import { ProcLog, initProcLog } from './ProcLog.js'
15+
import { ProcLog, initProcLog, EVENT_NAME } from './ProcLog.js'
1616

1717
export default Log
1818

19-
export { Log, LogEcs, logger, ProcLog, initProcLog, browserLogs, httpLogs }
19+
export {
20+
Log,
21+
LogEcs,
22+
logger,
23+
ProcLog,
24+
initProcLog,
25+
EVENT_NAME,
26+
browserLogs,
27+
httpLogs
28+
}

test/ProcLog.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert'
22
import { LogEcs } from '../src/index.js'
3-
import { ProcLog, initProcLog } from '../src/ProcLog.js'
3+
import { ProcLog, initProcLog, EVENT_NAME } from '../src/ProcLog.js'
44

55
describe('ProcLog', function () {
66
beforeEach(function () {
@@ -98,7 +98,7 @@ const myInitProcLog = () => {
9898
const reset = () => {
9999
lines = []
100100
}
101-
process.on('log', (...args) => {
101+
process.on(EVENT_NAME, (...args) => {
102102
lines.push(...args)
103103
})
104104
return { lines, reset }

types/ProcLog.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
* @param {LogOptionsWithCustomLog} [options]
44
*/
55
export function initProcLog(options?: LogOptionsWithCustomLog): void;
6+
/**
7+
* @typedef {import('./node.js').LogOptions} LogOptions
8+
*/
9+
/**
10+
* @typedef {LogOptions & {Log: typeof Log}} LogOptionsWithCustomLog
11+
*/
12+
export const EVENT_NAME: "log-level";
613
/**
714
* Decouple logging via process event 'log'. This allows to use a different
815
* logger framework than 'debug-level'. In such cases you'd need to adapt your

types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { LogEcs } from './ecs/LogEcs.js';
1414
import { logger } from './logger.js';
1515
import { ProcLog } from './ProcLog.js';
1616
import { initProcLog } from './ProcLog.js';
17+
import { EVENT_NAME } from './ProcLog.js';
1718
import { browserLogs } from './browserLogs.js';
1819
import { httpLogs } from './httpLogs.js';
19-
export { Log, LogEcs, logger, ProcLog, initProcLog, browserLogs, httpLogs };
20+
export { Log, LogEcs, logger, ProcLog, initProcLog, EVENT_NAME, browserLogs, httpLogs };

0 commit comments

Comments
 (0)