Skip to content

Commit 6ba19f7

Browse files
author
craigparra
committed
1.1.6 / pending
================== * clean nose, linting etc.
1 parent 4f0a60c commit 6ba19f7

19 files changed

+803
-453
lines changed

CachingConsole.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = class CachingConsole {
2-
32
static DEFAULT_SIZE = 1000;
4-
constructor(size,quiet) {
5-
this.cache = [];
3+
4+
constructor(size, quiet) {
5+
this.cache = [];
66
this.size = size || CachingConsole.DEFAULT_SIZE;
77
this.quiet = quiet == null ? true : quiet;
88
}
@@ -12,13 +12,13 @@ module.exports = class CachingConsole {
1212
if (this.cache.length > this.size) {
1313
this.cache.shift();
1414
}
15-
if (!this.quiet){
15+
if (!this.quiet) {
1616
// eslint-disable-next-line no-console
1717
console.log(line);
1818
}
1919
}
2020

21-
clear (){
21+
clear() {
2222
this.cache = [];
2323
}
2424
};

CachingLoggerFactory.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,33 @@ const CachingConsole = require('./CachingConsole');
33
const ConsoleLogger = require('./ConsoleLogger');
44
const LoggerFactory = require('./LoggerFactory');
55

6-
76
module.exports = class CachingLoggerFactory extends LoggerFactory {
7+
static getLogger(category, configArg, configPath, cache) {
8+
const $configArg = (typeof category === 'object' ? category : configArg);
9+
const $category = (typeof category === 'object' ? '' : category);
10+
return new ConfigurableLogger(LoggerFactory.detectConfig($configArg),
11+
new ConsoleLogger($category,
12+
null, null, null,
13+
LoggerFactory.getFormatter($configArg),
14+
new CachingConsole()),
15+
category,
16+
configPath,
17+
cache || LoggerFactory.loggerCategoryCache);
18+
}
819

9-
static getLogger(category, configArg, configPath, cache) {
10-
let _configArg = (typeof category == 'object' ? category : configArg);
11-
let _category = (typeof category == 'object' ? '' : category);
12-
return new ConfigurableLogger(LoggerFactory.detectConfig(_configArg),
13-
new ConsoleLogger(_category,
14-
null,null,null,
15-
LoggerFactory.getFormatter(_configArg),
16-
new CachingConsole()),
17-
category,
18-
configPath,
19-
cache || LoggerFactory.loggerCategoryCache);
20-
}
21-
22-
constructor(config, cache, configPath) {
23-
super (config, cache, configPath)
24-
CachingLoggerFactory.prototype.getFormatter = LoggerFactory.prototype.getFormatter;
25-
}
20+
constructor(config, cache, configPath) {
21+
super(config, cache, configPath);
22+
CachingLoggerFactory.prototype.getFormatter = LoggerFactory.prototype.getFormatter;
23+
}
2624

27-
getLogger(category) {
28-
return new ConfigurableLogger(this.config,
29-
new ConsoleLogger(category,
30-
null,null,null,
31-
this.getFormatter(this.config),
32-
new CachingConsole()),
33-
category,
34-
this.configPath,
35-
this.cache);
36-
}
25+
getLogger(category) {
26+
return new ConfigurableLogger(this.config,
27+
new ConsoleLogger(category,
28+
null, null, null,
29+
this.getFormatter(this.config),
30+
new CachingConsole()),
31+
category,
32+
this.configPath,
33+
this.cache);
34+
}
3735
};

ConfigurableLogger.js

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

44
module.exports = class ConfigurableLogger extends DelegatingLogger {
55
static DEFAULT_CONFIG_PATH = 'logging.level';
6+
67
constructor(config, provider, category, configPath, cache) {
78
super(provider);
89
this.config = config;
9-
if (!this.config){
10-
throw new Error ('config is required');
10+
if (!this.config) {
11+
throw new Error('config is required');
1112
}
1213
this.category = category || Logger.DEFAULT_CATEGORY;
1314
this.configPath = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
1415
this.cache = cache;
1516
if (!this.cache) {
16-
throw new Error ('cache is required');
17+
throw new Error('cache is required');
1718
}
1819
this.provider.setLevel(
1920
ConfigurableLogger.getLoggerLevel(

DelegatingLogger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = class DelegatingLogger {
22
constructor(provider) {
33
this.provider = provider;
4-
if (!this.provider){
5-
throw new Error ('provider is required');
4+
if (!this.provider) {
5+
throw new Error('provider is required');
66
}
77
}
88

JSONFormatter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = class JSONFormatter {
77
_.assignIn({
88
level, message, timestamp, category,
99
},
10-
_.assignIn(meta, this.meta)),
10+
meta),
1111
);
1212
}
1313
};

Logger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const LoggerLevel = require('./LoggerLevel');
22

33
module.exports = class Logger {
44
static DEFAULT_CATEGORY = 'ROOT'
5+
56
constructor(category, level, levels) {
67
this.category = category || Logger.DEFAULT_CATEGORY;
78
this.levels = levels || LoggerLevel.ENUMS;

LoggerFactory.js

Lines changed: 92 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,113 +7,114 @@ const PlainTextFormatter = require('./PlainTextFormatter');
77
module.exports = class LoggerFactory {
88
static loggerCategoryCache = new LoggerCategoryCache();
99

10-
static detectBrowser(){
11-
let browser = !(typeof window == 'undefined');
12-
return browser;
10+
static detectBrowser() {
11+
const browser = !(typeof window === 'undefined');
12+
return browser;
1313
}
1414

15-
static detectConfig(configArg){
16-
let _config = null;
17-
if (!(typeof config == 'undefined')){
18-
_config = config;
19-
}
20-
if (global?.boot?.contexts?.root?.config){
21-
_config = global.boot.contexts.root.config;
22-
}
23-
if (LoggerFactory.detectBrowser() && window?.config){
24-
_config = window.config;
25-
}
26-
if (LoggerFactory.detectBrowser() && window?.boot?.contexts?.root?.config){
27-
_config = window.boot.contexts.root.config;
28-
}
29-
_config = configArg || _config;
30-
if (_config){
31-
return _config;
32-
}
33-
else {
34-
throw new Error('Unable to detect config, is \'config\' declared or provided?')
35-
}
15+
static detectConfig(configArg) {
16+
let $config = null;
17+
if (!(typeof config === 'undefined')) {
18+
// eslint-disable-next-line no-undef
19+
$config = config;
20+
}
21+
if (global?.boot?.contexts?.root?.config) {
22+
$config = global.boot.contexts.root.config;
23+
}
24+
if (LoggerFactory.detectBrowser() && window?.config) {
25+
$config = window.config;
26+
}
27+
if (LoggerFactory.detectBrowser() && window?.boot?.contexts?.root?.config) {
28+
$config = window.boot.contexts.root.config;
29+
}
30+
$config = configArg || $config;
31+
if ($config) {
32+
return $config;
33+
}
34+
35+
throw new Error('Unable to detect config, is \'config\' declared or provided?');
3636
}
3737

38-
static detectLoggerFactory(){
39-
let _loggerFactory = null;
40-
if (!(typeof loggerFactory == 'undefined')){
41-
_loggerFactory = loggerFactory;
42-
}
43-
if (global?.boot?.contexts?.root?.loggerFactory){
44-
_loggerFactory = global.boot.contexts.root.loggerFactory;
45-
}
46-
if (LoggerFactory.detectBrowser() && window?.loggerFactory){
47-
_loggerFactory = window.loggerFactory;
48-
}
49-
if (LoggerFactory.detectBrowser() && window?.boot?.contexts?.root?.loggerFactory){
50-
_loggerFactory = window.boot.contexts.root.loggerFactory;
51-
}
52-
return _loggerFactory;
38+
static detectLoggerFactory() {
39+
let $loggerFactory = null;
40+
if (!(typeof loggerFactory === 'undefined')) {
41+
// eslint-disable-next-line no-undef
42+
$loggerFactory = loggerFactory;
43+
}
44+
if (global?.boot?.contexts?.root?.loggerFactory) {
45+
$loggerFactory = global.boot.contexts.root.loggerFactory;
46+
}
47+
if (LoggerFactory.detectBrowser() && window?.loggerFactory) {
48+
$loggerFactory = window.loggerFactory;
49+
}
50+
if (LoggerFactory.detectBrowser() && window?.boot?.contexts?.root?.loggerFactory) {
51+
$loggerFactory = window.boot.contexts.root.loggerFactory;
52+
}
53+
return $loggerFactory;
5354
}
5455

55-
static getFormatter(configArg){
56-
let format = 'json';
57-
let _config = this.detectConfig(configArg);
58-
if (LoggerFactory.detectBrowser()){
59-
format='text';
60-
}
61-
if (_config.has('logging.format')){
62-
format=_config.get('logging.format');
63-
}
64-
let formatter = (format.toLowerCase() === 'text') ? new PlainTextFormatter() : new JSONFormatter();
65-
return formatter
56+
static getFormatter(configArg) {
57+
let format = 'json';
58+
const $config = this.detectConfig(configArg);
59+
if (LoggerFactory.detectBrowser()) {
60+
format = 'text';
61+
}
62+
if ($config.has('logging.format')) {
63+
format = $config.get('logging.format');
64+
}
65+
const formatter = (format.toLowerCase() === 'text') ? new PlainTextFormatter() : new JSONFormatter();
66+
return formatter;
6667
}
6768

6869
static getLogger(category, configArg, configPath, cache) {
69-
let loggerFactory = this.detectLoggerFactory();
70-
if (loggerFactory){
71-
return loggerFactory.getLogger(category);
72-
}
73-
let _configArg = (typeof category == 'object' ? category : configArg);
74-
let _category = (typeof category == 'object' ? '' : category);
75-
return new ConfigurableLogger(LoggerFactory.detectConfig(_configArg),
76-
new ConsoleLogger(_category,
77-
null,null,null,
78-
LoggerFactory.getFormatter(_configArg),
79-
null),
80-
_category,
81-
configPath,
82-
cache || LoggerFactory.loggerCategoryCache);
70+
const loggerFactory = this.detectLoggerFactory();
71+
if (loggerFactory) {
72+
return loggerFactory.getLogger(category);
73+
}
74+
const $configArg = (typeof category === 'object' ? category : configArg);
75+
const $category = (typeof category === 'object' ? '' : category);
76+
return new ConfigurableLogger(LoggerFactory.detectConfig($configArg),
77+
new ConsoleLogger($category,
78+
null, null, null,
79+
LoggerFactory.getFormatter($configArg),
80+
null),
81+
$category,
82+
configPath,
83+
cache || LoggerFactory.loggerCategoryCache);
8384
}
8485

8586
constructor(config, cache, configPath) {
86-
this.config = config;
87-
this.cache = cache;
88-
this.configPath = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
89-
if (!this.config){
90-
throw new Error ('config is required');
91-
}
92-
if (!this.cache) {
93-
throw new Error ('cache is required');
94-
}
87+
this.config = config;
88+
this.cache = cache;
89+
this.configPath = configPath || ConfigurableLogger.DEFAULT_CONFIG_PATH;
90+
if (!this.config) {
91+
throw new Error('config is required');
92+
}
93+
if (!this.cache) {
94+
throw new Error('cache is required');
95+
}
9596
}
9697

9798
getLogger(category) {
98-
return new ConfigurableLogger(this.config,
99-
new ConsoleLogger(category,
100-
null,null,null,
101-
this.getFormatter(),
102-
null),
103-
category,
104-
this.configPath,
105-
this.cache);
99+
return new ConfigurableLogger(this.config,
100+
new ConsoleLogger(category,
101+
null, null, null,
102+
this.getFormatter(),
103+
null),
104+
category,
105+
this.configPath,
106+
this.cache);
106107
}
107108

108-
getFormatter(){
109-
let format = 'json';
110-
if (LoggerFactory.detectBrowser()){
111-
format='text';
112-
}
113-
if (this.config.has('logging.format')){
114-
format=this.config.get('logging.format')
115-
}
116-
let formatter = (format.toLowerCase() === 'text') ? new PlainTextFormatter() : new JSONFormatter();
117-
return formatter;
109+
getFormatter() {
110+
let format = 'json';
111+
if (LoggerFactory.detectBrowser()) {
112+
format = 'text';
113+
}
114+
if (this.config.has('logging.format')) {
115+
format = this.config.get('logging.format');
116+
}
117+
const formatter = (format.toLowerCase() === 'text') ? new PlainTextFormatter() : new JSONFormatter();
118+
return formatter;
118119
}
119120
};

WinstonLogger.js

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

55
module.exports = class WinstonLogger extends Logger {
6-
//category, level, levels, meta, formatter, consoleArg
6+
// category, level, levels, meta, formatter, consoleArg
77
constructor(category, level, levels, meta, winston, options) {
88
super(category, level, levels);
99
this.winston = winston;
10-
if (!this.winston){
11-
throw new Error ('winston is required');
10+
if (!this.winston) {
11+
throw new Error('winston is required');
1212
}
1313
this.meta = meta || {};
1414
this.options = options || {
1515
level: level || 'info',
1616
format: winston.format.combine(
17-
winston.format.timestamp(),
18-
winston.format.json(),
17+
winston.format.timestamp(),
18+
winston.format.json(),
1919
),
2020
defaultMeta: meta || {},
2121
transports: [

0 commit comments

Comments
 (0)