From f7f5f65bfc2d92f97f695a9343c160dec5ecd1e3 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 18 Mar 2022 03:59:58 +0800 Subject: [PATCH 1/7] chore(fix): when logger.level clones category from parent/default, to also clone over useCallStack --- lib/categories.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/categories.js b/lib/categories.js index 4e55918..1fb6ad2 100644 --- a/lib/categories.js +++ b/lib/categories.js @@ -193,6 +193,7 @@ const setLevelForCategory = (category, level) => { debug('setLevelForCategory: no config found for category, ' + `found ${sourceCategoryConfig} for parents of ${category}`); categoryConfig = { appenders: sourceCategoryConfig.appenders }; + categoryConfig.enableCallStack = sourceCategoryConfig.enableCallStack; } categoryConfig.level = level; categories.set(category, categoryConfig); From b383422d21357430aec4ae0bbd1fac11e1c93888 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 18 Mar 2022 04:02:48 +0800 Subject: [PATCH 2/7] chore(refactor): clone category from parent/default when it does not exist instead of during logger.level --- lib/categories.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/categories.js b/lib/categories.js index 1fb6ad2..a1c194e 100644 --- a/lib/categories.js +++ b/lib/categories.js @@ -141,6 +141,9 @@ configuration.addListener((config) => { const setup = (config) => { categories.clear(); + if (!config) { + return; + } const categoryNames = Object.keys(config.categories); categoryNames.forEach((name) => { @@ -162,7 +165,7 @@ const setup = (config) => { }; const init = () => { - setup({ categories: { default: { appenders: ['out'], level: 'OFF' } } }); + setup(); }; init(); @@ -174,29 +177,27 @@ const configForCategory = (category) => { debug(`configForCategory: ${category} exists in config, returning it`); return categories.get(category); } + + let sourceCategoryConfig; if (category.indexOf('.') > 0) { - debug(`configForCategory: ${category} has hierarchy, searching for parents`); - return configForCategory(category.substring(0, category.lastIndexOf('.'))); + debug(`configForCategory: ${category} has hierarchy, cloning from parents`); + sourceCategoryConfig = { ...configForCategory(category.substring(0, category.lastIndexOf('.'))) }; + } else { + if (!categories.has('default')) { + setup({ categories: { default: { appenders: ['out'], level: 'OFF' } } }); + } + debug('configForCategory: cloning default category'); + sourceCategoryConfig = { ...categories.get('default') }; } - debug('configForCategory: returning config for default category'); - return configForCategory('default'); + categories.set(category, sourceCategoryConfig); + return sourceCategoryConfig; }; const appendersForCategory = category => configForCategory(category).appenders; -const getLevelForCategory = category => configForCategory(category).level; +const getLevelForCategory = category => configForCategory(category).level; const setLevelForCategory = (category, level) => { - let categoryConfig = categories.get(category); - debug(`setLevelForCategory: found ${categoryConfig} for ${category}`); - if (!categoryConfig) { - const sourceCategoryConfig = configForCategory(category); - debug('setLevelForCategory: no config found for category, ' - + `found ${sourceCategoryConfig} for parents of ${category}`); - categoryConfig = { appenders: sourceCategoryConfig.appenders }; - categoryConfig.enableCallStack = sourceCategoryConfig.enableCallStack; - } - categoryConfig.level = level; - categories.set(category, categoryConfig); + configForCategory(category).level = level; }; const getEnableCallStackForCategory = category => configForCategory(category).enableCallStack === true; From 58bc58ae75d62b2e7979908d1300f880d31ab909 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 18 Mar 2022 04:03:16 +0800 Subject: [PATCH 3/7] chore(refactor): default level should be OFF --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index d1f84bd..ca36be5 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -60,7 +60,7 @@ class Logger { get level() { return levels.getLevel( categories.getLevelForCategory(this.category), - levels.TRACE + levels.OFF ); } From b4b8bbfef9a1977b99f4ecdb5ff753d410c372a8 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 18 Mar 2022 05:05:08 +0800 Subject: [PATCH 4/7] chore(test): added test cases --- test/tap/logger-test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/tap/logger-test.js b/test/tap/logger-test.js index 1a16710..6582dfb 100644 --- a/test/tap/logger-test.js +++ b/test/tap/logger-test.js @@ -3,12 +3,14 @@ const debug = require("debug")("log4js:test.logger"); const sandbox = require("@log4js-node/sandboxed-module"); const callsites = require("callsites"); const levels = require("../../lib/levels"); +const categories = require("../../lib/categories"); const events = []; const messages = []; const Logger = sandbox.require("../../lib/logger", { requires: { "./levels": levels, + "./categories": categories, "./clustering": { isMaster: () => true, onlyOnMaster: fn => fn(), @@ -272,5 +274,43 @@ test("../../lib/logger", batch => { t.end(); }); + batch.test("creating/cloning of category", t => { + const defaultLogger = new Logger("default"); + defaultLogger.level = "trace"; + defaultLogger.useCallStack = true; + + t.test("category should be cloned from parent/default if does not exist", assert => { + const originalLength = categories.size; + + const logger = new Logger("cheese1"); + assert.equal(categories.size, originalLength + 1, "category should be cloned"); + assert.equal(logger.level, levels.TRACE, "should inherit level=TRACE from default-category"); + assert.equal(logger.useCallStack, true, "should inherit useCallStack=true from default-category"); + assert.end(); + }); + + t.test("changing level should not impact default-category or useCallStack", assert => { + const logger = new Logger("cheese2"); + logger.level = "debug"; + assert.equal(logger.level, levels.DEBUG, "should be changed to level=DEBUG"); + assert.equal(defaultLogger.level, levels.TRACE, "default-category should remain as level=TRACE"); + assert.equal(logger.useCallStack, true, "should remain as useCallStack=true"); + assert.equal(defaultLogger.useCallStack, true, "default-category should remain as useCallStack=true"); + assert.end(); + }); + + t.test("changing useCallStack should not impact default-category or level", assert => { + const logger = new Logger("cheese3"); + logger.useCallStack = false; + assert.equal(logger.useCallStack, false, "should be changed to useCallStack=false"); + assert.equal(defaultLogger.useCallStack, true, "default-category should remain as useCallStack=true"); + assert.equal(logger.level, levels.TRACE, "should remain as level=TRACE"); + assert.equal(defaultLogger.level, levels.TRACE, "default-category should remain as level=TRACE"); + assert.end(); + }); + + t.end(); + }); + batch.end(); }); From b011fb9723cda8ef31ce1d29b62f195705d4f4b3 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 18 Mar 2022 05:16:13 +0800 Subject: [PATCH 5/7] chore(docs): added links to pages that were not accessible --- docs/_layouts/default.html | 1 + docs/appenders.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index e16f129..956b15b 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -25,6 +25,7 @@
  • Home
  • API
  • Appenders
  • +
  • Categories
  • Layouts
  • Terminology
  • FAQ
  • diff --git a/docs/appenders.md b/docs/appenders.md index 22c6d1c..0f536fd 100644 --- a/docs/appenders.md +++ b/docs/appenders.md @@ -27,6 +27,7 @@ The following appenders are included with log4js. Some require extra dependencie * [logLevelFilter](logLevelFilter.md) * [multiFile](multiFile.md) * [multiprocess](multiprocess.md) +* [noLogFilter](noLogFilter.md) * [recording](recording.md) * [stderr](stderr.md) * [stdout](stdout.md) From 10d944ed6c4862e641098481e6aa37f092529d71 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sun, 20 Mar 2022 19:06:48 +0800 Subject: [PATCH 6/7] chore(docs): fixed broken links --- docs/appenders.md | 2 +- docs/index.md | 2 +- docs/layouts.md | 4 ++-- docs/migration-guide.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/appenders.md b/docs/appenders.md index 0f536fd..a34c6b7 100644 --- a/docs/appenders.md +++ b/docs/appenders.md @@ -17,7 +17,7 @@ This defines two appenders named 'out' and 'app'. 'out' uses the [stdout](stdout ## Core Appenders -The following appenders are included with log4js. Some require extra dependencies that are not included as part of log4js (the [smtp](smtp.md) appender needs [nodemailer](https://www.npmjs.org/packages/nodemailer) for example), and these will be noted in the docs for that appender. If you don't use those appenders, then you don't need the extra dependencies. +The following appenders are included with log4js. Some require extra dependencies that are not included as part of log4js (the [smtp](https://github.com/log4js-node/smtp) appender needs [nodemailer](https://www.npmjs.com/package/nodemailer) for example), and these will be noted in the docs for that appender. If you don't use those appenders, then you don't need the extra dependencies. * [categoryFilter](categoryFilter.md) * [console](console.md) diff --git a/docs/index.md b/docs/index.md index ba8a54f..78da762 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ There have been a few changes between log4js 1.x and 2.x (and 0.x too). You shou - [GELF appender](https://github.com/log4js-node/gelf) - [Loggly appender](https://github.com/log4js-node/loggly) - [Logstash UDP appender](https://github.com/log4js-node/logstashUDP) -- logFaces ([UDP](logFaces-UDP.md) and [HTTP](logFaces-HTTP.md)) appender +- logFaces ([UDP](https://github.com/log4js-node/logFaces-UDP) and [HTTP](https://github.com/log4js-node/logFaces-HTTP)) appender - [TCP appender](tcp.md) (useful when you've got multiple servers but want to centralise logging) - a [logger for connect/express](connect-logger.md) servers - configurable log message [layout/patterns](layouts.md) diff --git a/docs/layouts.md b/docs/layouts.md index b2d2e45..b24bbca 100644 --- a/docs/layouts.md +++ b/docs/layouts.md @@ -2,7 +2,7 @@ Layouts are functions used by appenders to format log events for output. They take a log event as an argument and return a string. Log4js comes with several appenders built-in, and provides ways to create your own if these are not suitable. -For most use cases you will not need to configure layouts - there are some appenders which do not need layouts defined (for example, [logFaces-UDP](logFaces-UDP.md)); all the appenders that use layouts will have a sensible default defined. +For most use cases you will not need to configure layouts - there are some appenders which do not need layouts defined (for example, [logFaces-UDP](https://github.com/log4js-node/logFaces-UDP)); all the appenders that use layouts will have a sensible default defined. ## Configuration @@ -75,7 +75,7 @@ Cheese is too ripe! Cheese was: gouda * `type` - `dummy` -This layout only outputs the first value in the log event's data. It was added for the [logstashUDP](logstashUDP.md) appender, and I'm not sure there's much use for it outside that. +This layout only outputs the first value in the log event's data. It was added for the [logstashUDP](https://github.com/log4js-node/logstashUDP) appender, and I'm not sure there's much use for it outside that. ## Example ```javascript diff --git a/docs/migration-guide.md b/docs/migration-guide.md index c95af1c..8be8e4f 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -57,7 +57,7 @@ The `logFaces` appender was split into two versions to make testing easier and t Some appenders used to define their own `exit` listeners, and it was never clear whose responsibility it was to clean up resources. Now log4js does not define any `exit` listeners. Instead your application should register an `exit` listener, and call `log4js.shutdown` to be sure that all log messages get written before your application terminates. ## New Features -* MDC contexts - you can now add key-value pairs to a logger (for grouping all log messages from a particular user, for example). Support for these values exists in the [pattern layout](layouts.md), the [logFaces appenders](logFaces-UDP.md), and the [multi-file appender](multiFile.md). +* MDC contexts - you can now add key-value pairs to a logger (for grouping all log messages from a particular user, for example). Support for these values exists in the [pattern layout](layouts.md), the logFaces ([UDP](https://github.com/log4js-node/logFaces-UDP) and [HTTP](https://github.com/log4js-node/logFaces-HTTP)) appender, and the [multi-file appender](multiFile.md). * Automatic cluster support - log4js now handles clusters transparently * Custom levels - you can define your own log levels in the configuration object, including the colours * Improved performance - several changes have been made to improve performance, especially for the file appenders. From 96ca9dcc5f9028976b4ee26da5a810ccf39076ec Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 22 Mar 2022 11:12:43 +0800 Subject: [PATCH 7/7] chore(docs): updated changelog for 6.4.4 --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db3c68f..f11e1a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -# log4js-node changelog +# log4js-node Changelog + +## 6.4.4 + +- [chore(fix): set logger.level on runtime will no longer wrongly reset useCallStack](https://github.com/log4js-node/log4js-node/pull/1217) - thanks [@peteriman](https://github.com/peteriman) +- [chore(docs): updated docs for broken links and inaccessible pages](https://github.com/log4js-node/log4js-node/pull/1219) - thanks [@peteriman](https://github.com/peteriman) +- [chore(docs): broken link to gelf appender](https://github.com/log4js-node/log4js-node/pull/1218) - thanks [@mattalexx](https://github.com/mattalexx) +- [chore(docs): updated docs for appenders module loading](https://github.com/log4js-node/log4js-node/pull/985) - thanks [@leonimurilo](https://github.com/leonimurilo) ## 6.4.3