@athenna/logger 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Constants/VanillaChannels.d.ts +42 -0
- package/build/Constants/VanillaChannels.js +42 -0
- package/build/Exceptions/NotImplementedConfigException.d.ts +1 -1
- package/build/Exceptions/NotImplementedConfigException.js +4 -3
- package/build/Factories/DriverFactory.js +1 -1
- package/build/Formatters/Formatter.js +2 -2
- package/build/Formatters/NoneFormatter.js +1 -1
- package/build/Logger/Logger.d.ts +25 -10
- package/build/Logger/Logger.js +56 -18
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/package.json +1 -1
- package/build/Logger/VanillaLogger.d.ts +0 -65
- package/build/Logger/VanillaLogger.js +0 -93
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/logger
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Athenna default vanilla channels. This configurations
|
|
11
|
+
* will be used by the "channelOrVanilla" method. If the
|
|
12
|
+
* configuration does not exist, than the vanilla will be set.
|
|
13
|
+
*/
|
|
14
|
+
export declare const VANILLA_CHANNELS: {
|
|
15
|
+
default: {
|
|
16
|
+
driver: string;
|
|
17
|
+
channels: string[];
|
|
18
|
+
};
|
|
19
|
+
stack: {
|
|
20
|
+
driver: string;
|
|
21
|
+
channels: string[];
|
|
22
|
+
};
|
|
23
|
+
discard: {
|
|
24
|
+
driver: string;
|
|
25
|
+
};
|
|
26
|
+
console: {
|
|
27
|
+
level: string;
|
|
28
|
+
formatter: string;
|
|
29
|
+
driver: string;
|
|
30
|
+
};
|
|
31
|
+
exception: {
|
|
32
|
+
level: string;
|
|
33
|
+
formatter: string;
|
|
34
|
+
driver: string;
|
|
35
|
+
streamType: string;
|
|
36
|
+
};
|
|
37
|
+
application: {
|
|
38
|
+
level: string;
|
|
39
|
+
driver: string;
|
|
40
|
+
formatter: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/logger
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Athenna default vanilla channels. This configurations
|
|
11
|
+
* will be used by the "channelOrVanilla" method. If the
|
|
12
|
+
* configuration does not exist, than the vanilla will be set.
|
|
13
|
+
*/
|
|
14
|
+
export const VANILLA_CHANNELS = {
|
|
15
|
+
default: {
|
|
16
|
+
driver: 'stack',
|
|
17
|
+
channels: ['application'],
|
|
18
|
+
},
|
|
19
|
+
stack: {
|
|
20
|
+
driver: 'stack',
|
|
21
|
+
channels: ['application'],
|
|
22
|
+
},
|
|
23
|
+
discard: {
|
|
24
|
+
driver: 'null',
|
|
25
|
+
},
|
|
26
|
+
console: {
|
|
27
|
+
level: 'trace',
|
|
28
|
+
formatter: 'cli',
|
|
29
|
+
driver: 'console',
|
|
30
|
+
},
|
|
31
|
+
exception: {
|
|
32
|
+
level: 'trace',
|
|
33
|
+
formatter: 'none',
|
|
34
|
+
driver: 'console',
|
|
35
|
+
streamType: 'stderr',
|
|
36
|
+
},
|
|
37
|
+
application: {
|
|
38
|
+
level: 'trace',
|
|
39
|
+
driver: 'console',
|
|
40
|
+
formatter: 'simple',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Path, Exception } from '@athenna/common';
|
|
9
|
+
import { Path, Exception, Is } from '@athenna/common';
|
|
10
10
|
export class NotImplementedConfigException extends Exception {
|
|
11
|
-
constructor(channelName
|
|
11
|
+
constructor(channelName) {
|
|
12
12
|
let help = '';
|
|
13
|
-
|
|
13
|
+
const channels = Config.get('logging.channels');
|
|
14
|
+
if (channels && !Is.Empty(channels)) {
|
|
14
15
|
const availableConfigs = Object.keys(channels).join(', ');
|
|
15
16
|
help += `Available configurations are: ${availableConfigs}.`;
|
|
16
17
|
}
|
|
@@ -79,7 +79,7 @@ export class DriverFactory {
|
|
|
79
79
|
*/
|
|
80
80
|
static getChannelConfig(channelName) {
|
|
81
81
|
if (channelName === 'default') {
|
|
82
|
-
channelName = Config.get('logging.default'
|
|
82
|
+
channelName = Config.get('logging.default', channelName);
|
|
83
83
|
}
|
|
84
84
|
const channelConfig = Config.get(`logging.channels.${channelName}`);
|
|
85
85
|
if (!channelConfig) {
|
|
@@ -112,7 +112,7 @@ export class Formatter {
|
|
|
112
112
|
cliLevel() {
|
|
113
113
|
const level = this.configs.level;
|
|
114
114
|
if (!Color[level]) {
|
|
115
|
-
return level;
|
|
115
|
+
return Color.bold(`[ ${level} ]`);
|
|
116
116
|
}
|
|
117
117
|
return Color[level].bold(`[ ${level} ]`);
|
|
118
118
|
}
|
|
@@ -122,7 +122,7 @@ export class Formatter {
|
|
|
122
122
|
simpleLevel() {
|
|
123
123
|
const level = this.configs.level;
|
|
124
124
|
if (!Color[level]) {
|
|
125
|
-
return level;
|
|
125
|
+
return Color.bold(`[${level.toUpperCase()}]`);
|
|
126
126
|
}
|
|
127
127
|
return Color[level].bold(`[${level.toUpperCase()}]`);
|
|
128
128
|
}
|
package/build/Logger/Logger.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
10
9
|
export declare class Logger {
|
|
11
10
|
/**
|
|
12
11
|
* The drivers responsible for transporting the logs.
|
|
@@ -17,19 +16,38 @@ export declare class Logger {
|
|
|
17
16
|
*/
|
|
18
17
|
private runtimeConfigs;
|
|
19
18
|
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Create a new standalone logger instance. Very
|
|
21
|
+
* useful to create new loggers without changing the
|
|
22
|
+
* channels that are already defined in the main instance.
|
|
23
|
+
*/
|
|
24
|
+
static standalone(...configs: any[]): Logger;
|
|
20
25
|
/**
|
|
21
26
|
* Set runtime configurations for drivers and
|
|
22
27
|
* formatters.
|
|
23
28
|
*/
|
|
24
|
-
config(runtimeConfigs: any):
|
|
29
|
+
config(runtimeConfigs: any): Logger;
|
|
25
30
|
/**
|
|
26
31
|
* Change the log channel.
|
|
27
32
|
*/
|
|
28
|
-
channel(...channels: string[]):
|
|
33
|
+
channel(...channels: string[]): Logger;
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
35
|
+
* Change the log drivers using vanilla configurations.
|
|
36
|
+
* This method does not depend in Athenna configuration
|
|
37
|
+
* files to be executed.
|
|
31
38
|
*/
|
|
32
|
-
|
|
39
|
+
vanilla(...configs: any[]): Logger;
|
|
40
|
+
/**
|
|
41
|
+
* Verify if channel configuration exists. If not, Athenna will
|
|
42
|
+
* use the default vanilla configurations as drivers.
|
|
43
|
+
*/
|
|
44
|
+
channelOrVanilla(channel: string, configs?: {}): Logger;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new standalone logger instance. Very
|
|
47
|
+
* useful to create new loggers without changing the
|
|
48
|
+
* channels that are already defined in the main instance.
|
|
49
|
+
*/
|
|
50
|
+
standalone(...configs: any[]): Logger;
|
|
33
51
|
/**
|
|
34
52
|
* Creates a log of type trace in channel.
|
|
35
53
|
*/
|
|
@@ -59,10 +77,7 @@ export declare class Logger {
|
|
|
59
77
|
*/
|
|
60
78
|
fatal(...args: any[]): any | Promise<any>;
|
|
61
79
|
/**
|
|
62
|
-
*
|
|
63
|
-
* with vanilla configurations. By default,
|
|
64
|
-
* vanilla logger will use the "console" driver
|
|
65
|
-
* and "none" formatter.
|
|
80
|
+
* Call drivers to transport the log.
|
|
66
81
|
*/
|
|
67
|
-
|
|
82
|
+
private log;
|
|
68
83
|
}
|
package/build/Logger/Logger.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Color } from '@athenna/common';
|
|
10
10
|
import { Config } from '@athenna/config';
|
|
11
|
-
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
12
11
|
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
12
|
+
import { VANILLA_CHANNELS } from '../Constants/VanillaChannels.js';
|
|
13
13
|
export class Logger {
|
|
14
14
|
/**
|
|
15
15
|
* The drivers responsible for transporting the logs.
|
|
@@ -20,10 +20,17 @@ export class Logger {
|
|
|
20
20
|
*/
|
|
21
21
|
runtimeConfigs = {};
|
|
22
22
|
constructor() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
this.channelOrVanilla(Config.get('logging.default'));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a new standalone logger instance. Very
|
|
27
|
+
* useful to create new loggers without changing the
|
|
28
|
+
* channels that are already defined in the main instance.
|
|
29
|
+
*/
|
|
30
|
+
static standalone(...configs) {
|
|
31
|
+
const logger = new Logger();
|
|
32
|
+
logger.vanilla(...configs);
|
|
33
|
+
return logger;
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* Set runtime configurations for drivers and
|
|
@@ -38,18 +45,50 @@ export class Logger {
|
|
|
38
45
|
*/
|
|
39
46
|
channel(...channels) {
|
|
40
47
|
this.drivers = [];
|
|
41
|
-
channels.forEach(
|
|
42
|
-
this.drivers.push(DriverFactory.fabricate(
|
|
48
|
+
channels.forEach(channel => {
|
|
49
|
+
this.drivers.push(DriverFactory.fabricate(channel, this.runtimeConfigs));
|
|
43
50
|
});
|
|
44
51
|
return this;
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
|
-
*
|
|
54
|
+
* Change the log drivers using vanilla configurations.
|
|
55
|
+
* This method does not depend in Athenna configuration
|
|
56
|
+
* files to be executed.
|
|
48
57
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
vanilla(...configs) {
|
|
59
|
+
this.drivers = [];
|
|
60
|
+
if (!configs.length) {
|
|
61
|
+
this.drivers.push(DriverFactory.fabricateVanilla());
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
configs.forEach(config => {
|
|
65
|
+
this.drivers.push(DriverFactory.fabricateVanilla(config));
|
|
66
|
+
});
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Verify if channel configuration exists. If not, Athenna will
|
|
71
|
+
* use the default vanilla configurations as drivers.
|
|
72
|
+
*/
|
|
73
|
+
channelOrVanilla(channel, configs = {}) {
|
|
74
|
+
if (channel === 'default') {
|
|
75
|
+
channel = Config.get(`logging.channels.${Config.get('logging.default')}`, 'default');
|
|
76
|
+
}
|
|
77
|
+
if (Config.exists(`logging.channels.${channel}`)) {
|
|
78
|
+
return this.channel(channel);
|
|
79
|
+
}
|
|
80
|
+
return this.vanilla({
|
|
81
|
+
...VANILLA_CHANNELS[channel],
|
|
82
|
+
...configs,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a new standalone logger instance. Very
|
|
87
|
+
* useful to create new loggers without changing the
|
|
88
|
+
* channels that are already defined in the main instance.
|
|
89
|
+
*/
|
|
90
|
+
standalone(...configs) {
|
|
91
|
+
return Logger.standalone(...configs);
|
|
53
92
|
}
|
|
54
93
|
/**
|
|
55
94
|
* Creates a log of type trace in channel.
|
|
@@ -94,12 +133,11 @@ export class Logger {
|
|
|
94
133
|
return this.log('fatal', ...args);
|
|
95
134
|
}
|
|
96
135
|
/**
|
|
97
|
-
*
|
|
98
|
-
* with vanilla configurations. By default,
|
|
99
|
-
* vanilla logger will use the "console" driver
|
|
100
|
-
* and "none" formatter.
|
|
136
|
+
* Call drivers to transport the log.
|
|
101
137
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
138
|
+
async log(level, ...args) {
|
|
139
|
+
const message = Color.apply(...args);
|
|
140
|
+
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
141
|
+
return Promise.all(promises);
|
|
104
142
|
}
|
|
105
143
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export * from './Facades/Log.js';
|
|
|
10
10
|
export * from './Logger/Logger.js';
|
|
11
11
|
export * from './Drivers/Driver.js';
|
|
12
12
|
export * from './Formatters/Formatter.js';
|
|
13
|
-
export * from './Logger/VanillaLogger.js';
|
|
14
13
|
export * from './Helpers/FactoryHelper.js';
|
|
15
14
|
export * from './Factories/DriverFactory.js';
|
|
16
15
|
export * from './Providers/LoggerProvider.js';
|
package/build/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export * from './Facades/Log.js';
|
|
|
10
10
|
export * from './Logger/Logger.js';
|
|
11
11
|
export * from './Drivers/Driver.js';
|
|
12
12
|
export * from './Formatters/Formatter.js';
|
|
13
|
-
export * from './Logger/VanillaLogger.js';
|
|
14
13
|
export * from './Helpers/FactoryHelper.js';
|
|
15
14
|
export * from './Factories/DriverFactory.js';
|
|
16
15
|
export * from './Providers/LoggerProvider.js';
|
package/package.json
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/logger
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
export declare class VanillaLogger {
|
|
10
|
-
/**
|
|
11
|
-
* The driver responsible for transporting the logs.
|
|
12
|
-
*/
|
|
13
|
-
drivers: any[];
|
|
14
|
-
constructor(configs: any);
|
|
15
|
-
/**
|
|
16
|
-
* Log a simple log message without using the log driver
|
|
17
|
-
* but using the Color engine.
|
|
18
|
-
*/
|
|
19
|
-
simple(...args: any[]): void;
|
|
20
|
-
/**
|
|
21
|
-
* Set runtime configurations for drivers and
|
|
22
|
-
* formatters.
|
|
23
|
-
*/
|
|
24
|
-
config(): VanillaLogger;
|
|
25
|
-
/**
|
|
26
|
-
* Change the log channel.
|
|
27
|
-
*/
|
|
28
|
-
channel(): VanillaLogger;
|
|
29
|
-
/**
|
|
30
|
-
* Call drivers to transport the log.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} level
|
|
33
|
-
* @param {string} args
|
|
34
|
-
* @return {any | Promise<any>}
|
|
35
|
-
*/
|
|
36
|
-
private log;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a log of type trace in channel.
|
|
39
|
-
*/
|
|
40
|
-
trace(...args: any[]): any | Promise<any>;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a log of type debug in channel.
|
|
43
|
-
*/
|
|
44
|
-
debug(...args: any[]): any | Promise<any>;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a log of type info in channel.
|
|
47
|
-
*/
|
|
48
|
-
info(...args: any[]): any | Promise<any>;
|
|
49
|
-
/**
|
|
50
|
-
* Creates a log of type success in channel.
|
|
51
|
-
*/
|
|
52
|
-
success(...args: any[]): any | Promise<any>;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a log of type warn in channel.
|
|
55
|
-
*/
|
|
56
|
-
warn(...args: any[]): any | Promise<any>;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a log of type error in channel.
|
|
59
|
-
*/
|
|
60
|
-
error(...args: any[]): any | Promise<any>;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a log of type fatal in channel.
|
|
63
|
-
*/
|
|
64
|
-
fatal(...args: any[]): any | Promise<any>;
|
|
65
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/logger
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Color } from '@athenna/common';
|
|
10
|
-
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
11
|
-
export class VanillaLogger {
|
|
12
|
-
/**
|
|
13
|
-
* The driver responsible for transporting the logs.
|
|
14
|
-
*/
|
|
15
|
-
drivers = [];
|
|
16
|
-
constructor(configs) {
|
|
17
|
-
this.drivers.push(DriverFactory.fabricateVanilla(configs));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Log a simple log message without using the log driver
|
|
21
|
-
* but using the Color engine.
|
|
22
|
-
*/
|
|
23
|
-
simple(...args) {
|
|
24
|
-
process.stdout.write(Color.apply(...args).concat('\n'));
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Set runtime configurations for drivers and
|
|
28
|
-
* formatters.
|
|
29
|
-
*/
|
|
30
|
-
config() {
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Change the log channel.
|
|
35
|
-
*/
|
|
36
|
-
channel() {
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Call drivers to transport the log.
|
|
41
|
-
*
|
|
42
|
-
* @param {string} level
|
|
43
|
-
* @param {string} args
|
|
44
|
-
* @return {any | Promise<any>}
|
|
45
|
-
*/
|
|
46
|
-
log(level, ...args) {
|
|
47
|
-
const message = Color.apply(...args);
|
|
48
|
-
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
49
|
-
return Promise.all(promises);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Creates a log of type trace in channel.
|
|
53
|
-
*/
|
|
54
|
-
trace(...args) {
|
|
55
|
-
return this.log('trace', ...args);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates a log of type debug in channel.
|
|
59
|
-
*/
|
|
60
|
-
debug(...args) {
|
|
61
|
-
return this.log('debug', ...args);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Creates a log of type info in channel.
|
|
65
|
-
*/
|
|
66
|
-
info(...args) {
|
|
67
|
-
return this.log('info', ...args);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Creates a log of type success in channel.
|
|
71
|
-
*/
|
|
72
|
-
success(...args) {
|
|
73
|
-
return this.log('success', ...args);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Creates a log of type warn in channel.
|
|
77
|
-
*/
|
|
78
|
-
warn(...args) {
|
|
79
|
-
return this.log('warn', ...args);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Creates a log of type error in channel.
|
|
83
|
-
*/
|
|
84
|
-
error(...args) {
|
|
85
|
-
return this.log('error', ...args);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Creates a log of type fatal in channel.
|
|
89
|
-
*/
|
|
90
|
-
fatal(...args) {
|
|
91
|
-
return this.log('fatal', ...args);
|
|
92
|
-
}
|
|
93
|
-
}
|