Skip to content

Commit 5e86bd6

Browse files
author
craig
committed
1.1.5 / 2021-07-22
================== * Refactor categoryCache add -> put to be more resty/mapish - @craigparra * Refactor registry args -> cache - @craigparra
1 parent 7fca9b9 commit 5e86bd6

11 files changed

+52
-46
lines changed

CachingLoggerFactory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const LoggerFactory = require('./LoggerFactory');
66

77
module.exports = class CachingLoggerFactory extends LoggerFactory {
88

9-
static getLogger(category, configArg, configPath, registry) {
9+
static getLogger(category, configArg, configPath, cache) {
1010
let _configArg = (typeof category == 'object' ? category : configArg);
1111
let _category = (typeof category == 'object' ? '' : category);
1212
return new ConfigurableLogger(LoggerFactory.detectConfig(_configArg),
@@ -16,11 +16,11 @@ module.exports = class CachingLoggerFactory extends LoggerFactory {
1616
new CachingConsole()),
1717
category,
1818
configPath,
19-
registry || LoggerFactory.loggerCategoryCache);
19+
cache || LoggerFactory.loggerCategoryCache);
2020
}
2121

22-
constructor(config, registry, configPath) {
23-
super (config, registry, configPath)
22+
constructor(config, cache, configPath) {
23+
super (config, cache, configPath)
2424
CachingLoggerFactory.prototype.getFormatter = LoggerFactory.prototype.getFormatter;
2525
}
2626

@@ -32,6 +32,6 @@ module.exports = class CachingLoggerFactory extends LoggerFactory {
3232
new CachingConsole()),
3333
category,
3434
this.configPath,
35-
this.registry);
35+
this.cache);
3636
}
3737
};

ConfigurableLogger.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ const Logger = require('./Logger');
33

44
module.exports = class ConfigurableLogger extends DelegatingLogger {
55
static DEFAULT_CONFIG_PATH = 'logging.level';
6-
constructor(config, provider, category, configPath, registry) {
6+
constructor(config, provider, category, configPath, cache) {
77
super(provider);
88
this.config = config;
99
if (!this.config){
1010
throw new Error ('config is required');
1111
}
1212
this.category = category || Logger.DEFAULT_CATEGORY;
1313
this.configPath = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
14-
this.registry = registry;
15-
if (!this.registry) {
16-
throw new Error ('registry is required');
14+
this.cache = cache;
15+
if (!this.cache) {
16+
throw new Error ('cache is required');
1717
}
1818
this.provider.setLevel(
1919
ConfigurableLogger.getLoggerLevel(
2020
this.category,
2121
this.configPath,
2222
this.config,
23-
this.registry,
23+
this.cache,
2424
),
2525
);
2626

@@ -42,27 +42,27 @@ module.exports = class ConfigurableLogger extends DelegatingLogger {
4242
ConfigurableLogger.prototype.isFatalEnabled = DelegatingLogger.prototype.isFatalEnabled;
4343
}
4444

45-
static getLoggerLevel(category, configPath, config, registry) {
45+
static getLoggerLevel(category, configPath, config, cache) {
4646
let level = 'info';
4747
const path = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
4848
const categories = (category || '').split('/');
4949
let pathStep = path;
5050

5151
const root = `${pathStep}./`;
52-
if (registry.get(root)) {
53-
level = registry.get(root);
52+
if (cache.get(root)) {
53+
level = cache.get(root);
5454
} else if (config.has(root)) {
5555
level = config.get(root);
56-
registry.add(root, level);
56+
cache.put(root, level);
5757
}
5858

5959
for (let i = 0; i < categories.length; i++) {
6060
pathStep = `${pathStep}${i === 0 ? '.' : '/'}${categories[i]}`;
61-
if (registry.get(pathStep)) {
62-
level = registry.get(pathStep);
61+
if (cache.get(pathStep)) {
62+
level = cache.get(pathStep);
6363
} else if (config.has(pathStep)) {
6464
level = config.get(pathStep);
65-
registry.add(pathStep, level);
65+
cache.put(pathStep, level);
6666
}
6767
}
6868
return level;

History.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
1.1.5 / 2021-07-22
2+
==================
3+
4+
* Refactor categoryCache add -> put to be more resty/mapish - @craigparra
5+
* Refactor registry args -> cache - @craigparra
6+
17
1.1.4 / 2021-07-22
28
==================
39

4-
* Refactor reistry to categoryCache - @craigparra
10+
* Refactor registry to categoryCache - @craigparra
511

612
1.1.3 / 2021-07-20
713
==================

LoggerCategoryCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = class LoggerCategoryCache {
77
return this.cache[category];
88
}
99

10-
add(category, level) {
10+
put(category, level) {
1111
this.cache[category] = level;
1212
}
1313
};

LoggerFactory.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = class LoggerFactory {
6565
return formatter
6666
}
6767

68-
static getLogger(category, configArg, configPath, registry) {
68+
static getLogger(category, configArg, configPath, cache) {
6969
let loggerFactory = this.detectLoggerFactory();
7070
if (loggerFactory){
7171
return loggerFactory.getLogger(category);
@@ -79,18 +79,18 @@ module.exports = class LoggerFactory {
7979
null),
8080
_category,
8181
configPath,
82-
registry || LoggerFactory.loggerCategoryCache);
82+
cache || LoggerFactory.loggerCategoryCache);
8383
}
8484

85-
constructor(config, registry, configPath) {
85+
constructor(config, cache, configPath) {
8686
this.config = config;
87-
this.registry = registry;
87+
this.cache = cache;
8888
this.configPath = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
8989
if (!this.config){
9090
throw new Error ('config is required');
9191
}
92-
if (!this.registry) {
93-
throw new Error ('registry is required');
92+
if (!this.cache) {
93+
throw new Error ('cache is required');
9494
}
9595
}
9696

@@ -102,7 +102,7 @@ module.exports = class LoggerFactory {
102102
null),
103103
category,
104104
this.configPath,
105-
this.registry);
105+
this.cache);
106106
}
107107

108108
getFormatter(){

WinstonLoggerFactory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ const WinstonLogger = require('./WinstonLogger');
44

55
module.exports = class WinstonLoggerFactory {
66

7-
static getLogger(category, config, winston, options, configPath, registry) {
7+
static getLogger(category, config, winston, options, configPath, cache) {
88
//constructor(category, level, levels, meta, winston, options)
99
return new ConfigurableLogger(config,
1010
new WinstonLogger(category,null,null,null,winston,options),
1111
category,
1212
configPath,
13-
registry || LoggerFactory.loggerCategoryCache);
13+
cache || LoggerFactory.loggerCategoryCache);
1414
}
1515

16-
constructor(config,winston,options,registry, configPath) {
16+
constructor(config,winston,options,cache, configPath) {
1717
this.config = config;
1818
this.winston = winston;
1919
this.options = options;
20-
this.registry = registry;
20+
this.cache = cache;
2121
this.configPath = configPath;
2222
}
2323

@@ -26,7 +26,7 @@ module.exports = class WinstonLoggerFactory {
2626
new WinstonLogger(category,null,null,null,this.winston,this.options),
2727
category,
2828
this.configPath,
29-
this.registry
29+
this.cache
3030
);
3131
}
3232
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alt-javascript/logger",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "A simple configurable logging facade for javascript.",
55
"author": "",
66
"keywords": [

test/CachingLoggerFactory.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('CachingLoggerFactory Specification', () => {
4141
const cachingLoggerFactory = new CachingLoggerFactory(config,registry,ConfigurableLogger.DEFAULT_CONFIG_PATH);
4242

4343
assert.equal(cachingLoggerFactory.config, config, 'cachingLoggerFactory.config === config');
44-
assert.equal(cachingLoggerFactory.registry, registry, 'cachingLoggerFactory.registry === registry');
44+
assert.equal(cachingLoggerFactory.cache, registry, 'cachingLoggerFactory.registry === registry');
4545
assert.equal(cachingLoggerFactory.configPath, ConfigurableLogger.DEFAULT_CONFIG_PATH, 'cachingLoggerFactory.configPath === configPath');
4646
});
4747

@@ -54,7 +54,7 @@ describe('CachingLoggerFactory Specification', () => {
5454
assert.equal(logger.config, config, 'logger.config === config');
5555
assert.equal(logger.category, Logger.DEFAULT_CATEGORY, 'logger.category === Logger.DEFAULT_CATEGORY');
5656
assert.equal(logger.configPath, ConfigurableLogger.DEFAULT_CONFIG_PATH, 'logger.configPath === ConfigurableLogger.DEFAULT_CONFIG_PATH');
57-
assert.equal(logger.registry, registry, 'logger.registry === registry');
57+
assert.equal(logger.cache, registry, 'logger.registry === registry');
5858
});
5959

6060
it('static getLogger Unable to detect config,', () => {

test/ConfigurableLogger.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ describe('ConfigurableLogger Specification', () => {
4040
it('Instantiate - constructor args are set', () => {
4141
const config = new EphemeralConfig({});
4242
const consoleLogger = new ConsoleLogger(Logger.DEFAULT_CATEGORY,LoggerLevel.DEBUG,LoggerLevel.ENUMS,{},new JSONFormatter(), new CachingConsole(10,true));
43-
const registry = new LoggerCategoryCache();
44-
const logger = new ConfigurableLogger(config,consoleLogger,Logger.DEFAULT_CATEGORY,ConfigurableLogger.DEFAULT_CONFIG_PATH,registry);
43+
const cache = new LoggerCategoryCache();
44+
const logger = new ConfigurableLogger(config,consoleLogger,Logger.DEFAULT_CATEGORY,ConfigurableLogger.DEFAULT_CONFIG_PATH,cache);
4545

46-
// constructor(config, provider, category, configPath, registry) {
46+
// constructor(config, provider, category, configPath, cache) {
4747
assert.equal(logger.config, config, 'logger.config === config');
4848
assert.equal(logger.provider, consoleLogger, 'logger.provider === consoleLogger');
4949
assert.equal(logger.category, Logger.DEFAULT_CATEGORY, 'logger.category === Logger.DEFAULT_CATEGORY');
5050
assert.equal(logger.configPath, ConfigurableLogger.DEFAULT_CONFIG_PATH, 'logger.configPath === ConfigurableLogger.DEFAUL_CONFIG_PATH');
51-
assert.equal(logger.registry, registry, 'logger.registry === registry');
51+
assert.equal(logger.cache, cache, 'logger.cache === cache');
5252
});
5353

5454
it('Instantiate - default constructor args are set', () => {
5555
const config = new EphemeralConfig({});
56-
const registry = new LoggerCategoryCache();
56+
const cache = new LoggerCategoryCache();
5757
const consoleLogger = new ConsoleLogger(Logger.DEFAULT_CATEGORY,LoggerLevel.DEBUG,LoggerLevel.ENUMS,{},new JSONFormatter(), new CachingConsole(10,true));
58-
const logger = new ConfigurableLogger(config,consoleLogger,null,null,registry);
58+
const logger = new ConfigurableLogger(config,consoleLogger,null,null,cache);
5959

6060
assert.equal(logger.config, config, 'logger.config === config');
6161
assert.equal(logger.provider, consoleLogger, 'logger.provider === consoleLogger');
6262
assert.equal(logger.category, Logger.DEFAULT_CATEGORY, 'logger.category === Logger.DEFAULT_CATEGORY');
6363
assert.equal(logger.configPath, ConfigurableLogger.DEFAULT_CONFIG_PATH, 'logger.configPath === ConfigurableLogger.DEFAUL_CONFIG_PATH');
64-
assert.equal(logger.registry, registry, 'logger.registry === registry');
64+
assert.equal(logger.cache, cache, 'logger.cache === cache');
6565
});
6666

6767
it('Instantiate - config is required', () => {
@@ -79,7 +79,7 @@ describe('ConfigurableLogger Specification', () => {
7979
it('Instantiate - provider is required', () => {
8080
const config = new EphemeralConfig({});
8181
const consoleLogger = new ConsoleLogger(Logger.DEFAULT_CATEGORY,LoggerLevel.DEBUG,LoggerLevel.ENUMS,{},new JSONFormatter(), new CachingConsole(10,true));
82-
assert.throws(()=>{new ConfigurableLogger(config,consoleLogger,null,null)},'registry is required');
82+
assert.throws(()=>{new ConfigurableLogger(config,consoleLogger,null,null)},'cache is required');
8383
});
8484

8585

@@ -89,7 +89,7 @@ describe('ConfigurableLogger Specification', () => {
8989
logger.setLevel(LoggerLevel.DEBUG);
9090
assert.equal(logger.provider.level, LoggerLevel.ENUMS[LoggerLevel.DEBUG], 'logger.level === LoggerLevels.ENUMS[LoggerLevel.DEBUG]');
9191
});
92-
92+
9393

9494
it('Check levels - debug', () => {
9595
const config = new EphemeralConfig({logging:{level:{'/':LoggerLevel.DEBUG}}});

test/LoggerCategoryCache.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('LoggerCategoryCache Specification', () => {
4040

4141
it('add', () => {
4242
const loggerCategoryCache = new LoggerCategoryCache();
43-
loggerCategoryCache.add('ROOT', LoggerLevel.DEBUG);
43+
loggerCategoryCache.put('ROOT', LoggerLevel.DEBUG);
4444
assert.equal(loggerCategoryCache.get('ROOT'), LoggerLevel.DEBUG, 'loggerCategoryCache.get(\'ROOT\') === LoggerLevel.DEBUG');
4545
});
4646

0 commit comments

Comments
 (0)