Skip to content

Commit 90f6f3d

Browse files
author
Zachary Haber
committed
chore: fix review suggestions
1 parent 314c18e commit 90f6f3d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function getErrorStack(logData) {
2323
return null;
2424
}
2525

26+
const NUM_REQUIRED_PROPERTIES = 5;
27+
2628
/**
2729
*
2830
* For HTTP (browsers or node.js) use the following configuration params:
@@ -102,11 +104,12 @@ function logFacesAppender(config) {
102104
if (
103105
typeof lfsEvent !== 'object' ||
104106
Array.isArray(lfsEvent) ||
105-
Object.keys(lfsEvent).length < 3
107+
// require at least the number of required properties ignoring `m`
108+
Object.keys(lfsEvent).length < NUM_REQUIRED_PROPERTIES - 1
106109
) {
107110
// eslint-disable-next-line no-console
108111
console.error(
109-
`log4js.logFaces-HTTP Appender eventLayout must be an object`
112+
`log4js.logFaces-HTTP Appender eventLayout() must return an object`
110113
);
111114
return;
112115
}

test/tap/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ test('logFaces appender', (batch) => {
261261
},
262262
});
263263
const message =
264-
'log4js.logFaces-HTTP Appender eventLayout must be an object';
264+
'log4js.logFaces-HTTP Appender eventLayout() must return an object';
265265
['array', 'string', 'object'].forEach((input) => {
266266
setup.logger.info(input);
267267
t.equal(setup.fakeConsole.msg, message);

types/index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type { Agent as httpAgent } from 'http';
22
import type { Agent as httpsAgent } from 'https';
33
import type { LoggingEvent } from 'log4js';
44

5+
/** https://stackoverflow.com/a/53742583/13175138 */
6+
type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
7+
58
export interface LogFacesHTTPAppender {
69
type: '@log4js-node/logfaces-http';
710
/** logFaces receiver servlet URL */
@@ -34,7 +37,7 @@ export interface LogFacesHTTPAppender {
3437
export type LogFacesLayoutFunction = (
3538
loggingEvent: LoggingEvent,
3639
logFacesEvent: Omit<LogFacesEvent, 'm'>
37-
) => LogFacesEvent | undefined | null;
40+
) => PickPartial<LogFacesEvent, 'm'> | undefined | null;
3841

3942
/** [Data model: Log events](http://www.moonlit-software.com/logfaces/downloads/logfaces-manual.pdf) */
4043
export interface LogFacesEvent {
@@ -51,7 +54,7 @@ export interface LogFacesEvent {
5154
/** Name of the thread originating the event */
5255
r?: string;
5356
/** Message Content */
54-
m?: string;
57+
m: string;
5558
/** [Network Diagnostic Context](http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html) */
5659
n?: string;
5760
/** Indication whether the event is a thrown exception */

0 commit comments

Comments
 (0)