Skip to content

Commit

Permalink
Make typings match code better
Browse files Browse the repository at this point in the history
Fixes v6.4.0 regressions.

There is an npm script `npm run typings` which actually failed before
this commit. This seems to have been a combination of incorrect typings
(a mandatory argument to `getLevel` that should be optional, the idea
that for custom appenders `configure` should return an intermediate
"generator" function before the appender function itself) as well as
mistakes in the test file (which had an appender module which had one
level of function nesting too few).

Specifically, for the `configure` function on appenders, I believe there
should be two levels of function: an outer function taking one-time
configuration, and an inner function taking an individual log messages.
The typings file wanted there to be three layers, and the test file
wanted there to be one layer.

Fixes #1155.
  • Loading branch information
glasser committed Jan 21, 2022
1 parent 9c9c79b commit 58234af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions types/log4js.d.ts
Expand Up @@ -263,14 +263,9 @@ export interface CustomAppender {
}

export interface AppenderModule {
configure: (config: Config, layouts: LayoutsParam) => AppenderGenerator;
configure: (config: Config, layouts: LayoutsParam) => AppenderFunction;
}

export type AppenderGenerator = (
layout: LayoutFunction,
timezoneOffset?: string
) => AppenderFunction;

export type AppenderFunction = (loggingEvent: LoggingEvent) => void;

// TODO: Actually add types here...
Expand Down Expand Up @@ -321,7 +316,7 @@ export interface Levels {
FATAL: Level;
OFF: Level;
levels: Level[];
getLevel(level: Level | string, defaultLevel: Level): Level;
getLevel(level: Level | string, defaultLevel?: Level): Level;
addLevels(customLevels: object): void;
}

Expand Down
2 changes: 1 addition & 1 deletion types/test.ts
Expand Up @@ -133,7 +133,7 @@ log4js.connectLogger(logger2, {

//support for passing in an appender module
log4js.configure({
appenders: { thing: { type: { configure: () => {} }}},
appenders: { thing: { type: { configure: () => () => {} }}},
categories: { default: { appenders: ['thing'], level: 'debug'}}
});

Expand Down

1 comment on commit 58234af

@nicobao
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was merged @glasser

Please sign in to comment.