From 18ad6530442b3044d5fa5b341506a9d66de03b65 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Wed, 4 Jul 2018 18:16:41 +0200 Subject: [PATCH 1/2] fix(typings): correctly type the `levels` property --- types/log4js.d.ts | 19 +++++++++++++------ types/test.ts | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/types/log4js.d.ts b/types/log4js.d.ts index 1720ca1..88ade72 100644 --- a/types/log4js.d.ts +++ b/types/log4js.d.ts @@ -6,7 +6,7 @@ export interface Log4js { configure(config: Configuration): Log4js; addLayout(name: string, config: (a: any) => (logEvent: LoggingEvent) => string): void; connectLogger(logger: Logger, options: { format?: string; level?: string; nolog?: any; }): any; // express.Handler; - levels(): Levels; + levels: Levels; shutdown(cb?: (error: Error) => void): void | null; } @@ -19,7 +19,7 @@ export function addLayout(name: string, config: (a: any) => (logEvent: LoggingEv export function connectLogger(logger: Logger, options: { format?: string; level?: string; nolog?: any; }): any; // express.Handler; -export function levels(): Levels; +export const levels: Levels; export function shutdown(cb?: (error: Error) => void): void | null; @@ -409,10 +409,17 @@ export type Appender = CategoryFilterAppender | CustomAppender; export interface Levels { - [index: string]: { - value: number; - colour: string; - }; + ALL: Level; + MARK: Level; + TRACE: Level; + DEBUG: Level; + INFO: Level; + WARN: Level; + ERROR: Level; + FATAL: Level; + OFF: Level; + levels: Level[]; + getLevel(level: string): Level; } export interface Configuration { diff --git a/types/test.ts b/types/test.ts index 18e8647..092eb52 100644 --- a/types/test.ts +++ b/types/test.ts @@ -117,3 +117,6 @@ log4js.configure('./filename').getLogger(); const logger7 = log4js.getLogger(); logger7.level = 'debug'; logger7.debug("Some debug messages"); + +const levels: log4js.Levels = log4js.levels; +const level: log4js.Level = levels.getLevel('info'); From 29a238a7268de5ae431b7e08cb686b7ac12beff5 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 6 Jul 2018 07:48:04 +1000 Subject: [PATCH 2/2] chore: deprecated logFaces-HTTP appender --- docs/appenders.md | 2 +- docs/logFaces-HTTP.md | 31 ------------------------------- lib/appenders/logFaces-HTTP.js | 8 +++++++- 3 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 docs/logFaces-HTTP.md diff --git a/docs/appenders.md b/docs/appenders.md index b6d3014..7eb494f 100644 --- a/docs/appenders.md +++ b/docs/appenders.md @@ -24,7 +24,6 @@ The following appenders are included with log4js. Some require extra dependencie * [dateFile](dateFile.md) * [file](file.md) * [fileSync](fileSync.md) -* [logFaces-HTTP](logFaces-HTTP.md) * [logFaces-UDP](logFaces-UDP.md) * [logLevelFilter](logLevelFilter.md) * [multiFile](multiFile.md) @@ -39,6 +38,7 @@ The following appenders are supported by log4js, but will issue deprecation warn * [gelf](https://github.com/log4js-node/gelf) * [hipchat](https://github.com/log4js-node/hipchat) +* [logFaces-HTTP](https://github.com/log4js-node/logFaces-HTTP) * [loggly](https://github.com/log4js-node/loggly) * [logstashHTTP](https://github.com/log4js-node/logstashHTTP) * [logstashUDP](https://github.com/log4js-node/logstashUDP) diff --git a/docs/logFaces-HTTP.md b/docs/logFaces-HTTP.md deleted file mode 100644 index f60b38a..0000000 --- a/docs/logFaces-HTTP.md +++ /dev/null @@ -1,31 +0,0 @@ -# logFaces Appender (HTTP) - -The logFaces appenders send JSON formatted log events to [logFaces](http://www.moonlit-software.com) receivers. This appender uses HTTP to send the events (there is another logFaces appender that uses [UDP](logFaces-UDP.md)). You will need to include [axios](https://www.npmjs.com/package/axios) in your dependencies to use this appender. - -## Configuration - -* `type` - `logFaces-HTTP` -* `url` - `string` - logFaces receiver servlet URL -* `application` - `string` (optional, defaults to empty string) - used to identify your application's logs -* `timeout` - `integer` (optional, defaults to 5000ms) - the timeout for the HTTP request. - -This appender will also pick up Logger context values from the events, and add them as `p_` values in the logFaces event. See the example below for more details. - -# Example (default config) - -```javascript -log4js.configure({ - appenders: { - logfaces: { type: 'logFaces-HTTP', url: 'http://lfs-server/logs' } - }, - categories: { - default: { appenders: [ 'logfaces' ], level: 'info' } - } -}); - -const logger = log4js.getLogger(); -logger.addContext('requestId', '123'); -logger.info('some interesting log message'); -logger.error('something has gone wrong'); -``` -This example will result in two log events being sent to `lfs-server`. Both events will have a `p_requestId` property with a value of `123`. diff --git a/lib/appenders/logFaces-HTTP.js b/lib/appenders/logFaces-HTTP.js index d596a2a..397a02c 100644 --- a/lib/appenders/logFaces-HTTP.js +++ b/lib/appenders/logFaces-HTTP.js @@ -1,4 +1,7 @@ /** + * This appender is deprecated. All bugfixes and improvements should be made in + * https://github.com/log4js-node/logFaces-HTTP + * * logFaces appender sends JSON formatted log events to logFaces receivers. * There are two types of receivers supported - raw UDP sockets (for server side apps), * and HTTP (for client side apps). Depending on the usage, this appender @@ -33,7 +36,7 @@ function logFacesAppender(config) { withCredentials: true }); - return function log(event) { + const appender = function log(event) { // convert to logFaces compact json format const lfsEvent = { a: config.application || '', // application name @@ -58,6 +61,9 @@ function logFacesAppender(config) { console.error(`log4js.logFaces-HTTP Appender error: ${error.message}`); }); }; + + appender.deprecated = '@log4js-node/logfaces-http'; + return appender; } function configure(config) {