@creejs/commons-logging 1.0.0 → 2.0.0
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/lib/index.js +3 -1
- package/lib/log-config.js +14 -8
- package/lib/log-level.js +6 -0
- package/lib/provider-type.js +9 -0
- package/package.json +4 -8
- package/types/console/console-log-factory.d.ts +19 -0
- package/types/console/console-log-provider.d.ts +13 -0
- package/types/console/console-logger.d.ts +26 -0
- package/types/console/index.d.ts +3 -0
- package/types/index.d.ts +60 -14
- package/types/log-config.d.ts +89 -0
- package/types/log-factory.d.ts +55 -0
- package/types/log-level.d.ts +93 -0
- package/types/log4js/index.d.ts +3 -0
- package/types/log4js/log4js-6x-config.d.ts +13 -0
- package/types/log4js/log4js-factory.d.ts +17 -0
- package/types/log4js/log4js-logger.d.ts +13 -0
- package/types/log4js/log4js-provider.d.ts +13 -0
- package/types/logger.d.ts +112 -49
- package/types/provider-type.d.ts +10 -0
- package/types/provider.d.ts +32 -0
package/lib/index.js
CHANGED
|
@@ -54,7 +54,9 @@ function setLevel (level) {
|
|
|
54
54
|
LogConfig.currentLevel = levelNumber
|
|
55
55
|
|
|
56
56
|
// refresh existed factories
|
|
57
|
-
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
// eslint-disable-next-line no-unused-vars
|
|
59
|
+
for (const [typeName, factory] of LogConfig.listFactories()) {
|
|
58
60
|
factory.setLevel(levelNumber)
|
|
59
61
|
}
|
|
60
62
|
// refresh existed Loggers
|
package/lib/log-config.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
/**
|
|
3
|
+
* @module LogConfig
|
|
4
|
+
* @description Provide Impl of Log Configuration
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
2
7
|
// internal
|
|
3
8
|
const { TypeAssert: { assertString } } = require('@creejs/commons-lang')
|
|
4
9
|
// owned
|
|
@@ -36,11 +41,12 @@ const type2Provider = new Map()
|
|
|
36
41
|
* @param {string} typeName - The type identifier for the provider.
|
|
37
42
|
* @param {Provider} provider - The logging provider implementation.
|
|
38
43
|
* @returns {void}
|
|
44
|
+
* @alias module:LogConfig.addProvider
|
|
39
45
|
*/
|
|
40
46
|
function addProvider (typeName, provider) {
|
|
41
47
|
assertString(typeName)
|
|
42
48
|
Provider.assertProviderLike(provider)
|
|
43
|
-
type2Provider.set(typeName, provider)
|
|
49
|
+
type2Provider.set(typeName.toUpperCase(), provider)
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
/**
|
|
@@ -50,7 +56,7 @@ function addProvider (typeName, provider) {
|
|
|
50
56
|
*/
|
|
51
57
|
function getProvider (typeName) {
|
|
52
58
|
assertString(typeName)
|
|
53
|
-
return type2Provider.get(typeName)
|
|
59
|
+
return type2Provider.get(typeName.toUpperCase())
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
/**
|
|
@@ -60,7 +66,7 @@ function getProvider (typeName) {
|
|
|
60
66
|
*/
|
|
61
67
|
function removeProvider (typeName) {
|
|
62
68
|
assertString(typeName)
|
|
63
|
-
return type2Provider.delete(typeName)
|
|
69
|
+
return type2Provider.delete(typeName.toUpperCase())
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
function clearProviders () {
|
|
@@ -70,7 +76,7 @@ function clearProviders () {
|
|
|
70
76
|
/**
|
|
71
77
|
* Returns an array of all registered factory types and intances.
|
|
72
78
|
* 1. Each entry is a [type, factory] pair
|
|
73
|
-
* @returns {Array<
|
|
79
|
+
* @returns {Array<{0:string, 1:Provider}>} An array of factory entries.
|
|
74
80
|
*/
|
|
75
81
|
function listProviders () {
|
|
76
82
|
return [...type2Provider.entries()]
|
|
@@ -91,7 +97,7 @@ const type2Factory = new Map()
|
|
|
91
97
|
function addFactory (typeName, logFactory) {
|
|
92
98
|
assertString(typeName)
|
|
93
99
|
LogFactory.assertLogFactoryLike(logFactory)
|
|
94
|
-
type2Factory.set(typeName, logFactory)
|
|
100
|
+
type2Factory.set(typeName.toUpperCase(), logFactory)
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
/**
|
|
@@ -101,7 +107,7 @@ function addFactory (typeName, logFactory) {
|
|
|
101
107
|
*/
|
|
102
108
|
function removeFactory (typeName) {
|
|
103
109
|
assertString(typeName)
|
|
104
|
-
return type2Factory.delete(typeName)
|
|
110
|
+
return type2Factory.delete(typeName.toUpperCase())
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
/**
|
|
@@ -111,7 +117,7 @@ function removeFactory (typeName) {
|
|
|
111
117
|
*/
|
|
112
118
|
function getFactory (typeName) {
|
|
113
119
|
assertString(typeName)
|
|
114
|
-
return type2Factory.get(typeName)
|
|
120
|
+
return type2Factory.get(typeName.toUpperCase())
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
/**
|
|
@@ -125,7 +131,7 @@ function clearFactories () {
|
|
|
125
131
|
/**
|
|
126
132
|
* Returns an array of all registered factory types and intances.
|
|
127
133
|
* 1. Each entry is a [type, factory] pair
|
|
128
|
-
* @returns {Array<
|
|
134
|
+
* @returns {Array<{0:string, 1:LogFactory}>} An array of factory entries.
|
|
129
135
|
*/
|
|
130
136
|
function listFactories () {
|
|
131
137
|
return [...type2Factory.entries()]
|
package/lib/log-level.js
CHANGED
|
@@ -102,6 +102,8 @@ function name2Value (name) {
|
|
|
102
102
|
* Checks if the given level is a valid log level.
|
|
103
103
|
* @param {number} level - The log level to check.
|
|
104
104
|
* @returns {boolean} True if the level is valid, false otherwise.
|
|
105
|
+
* @memberof LogLevel
|
|
106
|
+
* @static
|
|
105
107
|
*/
|
|
106
108
|
function hasLevel (level) {
|
|
107
109
|
return Value2Name.has(level)
|
|
@@ -111,6 +113,8 @@ function hasLevel (level) {
|
|
|
111
113
|
* Checks if the given level name exists in the Name enum/object.
|
|
112
114
|
* @param {string} levelName - The name of the log level to check.
|
|
113
115
|
* @returns {boolean} True if the level name exists, false otherwise.
|
|
116
|
+
* @memberof LogLevel
|
|
117
|
+
* @static
|
|
114
118
|
*/
|
|
115
119
|
function hasName (levelName) {
|
|
116
120
|
if (!isString(levelName)) {
|
|
@@ -123,6 +127,8 @@ function hasName (levelName) {
|
|
|
123
127
|
* Validates that a given level is a number and falls within the valid range.
|
|
124
128
|
* @param {*} level - The log level to validate
|
|
125
129
|
* @throws {Error} If level is not a number or outside valid range (Level.OFF to Level.ALL)
|
|
130
|
+
* @memberof LogLevel
|
|
131
|
+
* @static
|
|
126
132
|
*/
|
|
127
133
|
function assertLevel (level) {
|
|
128
134
|
if (!isNumber(level)) {
|
package/lib/provider-type.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
/**
|
|
3
|
+
* @type {string}
|
|
4
|
+
* @memberof ProviderType
|
|
5
|
+
*/
|
|
2
6
|
const Log4js = 'LOG4JS'
|
|
7
|
+
/**
|
|
8
|
+
* @type {string}
|
|
9
|
+
* @memberof ProviderType
|
|
10
|
+
*/
|
|
3
11
|
const Console = 'CONSOLE'
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* @namespace ProviderType
|
|
6
15
|
* @description Define the static types
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creejs/commons-logging",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Common Utils About Logging",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"private": false,
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"types/",
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
|
+
"types": "types/index.d.ts",
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public"
|
|
15
16
|
},
|
|
@@ -19,16 +20,11 @@
|
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"dts": "tsc",
|
|
22
|
-
"generate-docs": "node_modules/.bin/jsdoc -c ./jsdoc.json"
|
|
23
|
+
"generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json"
|
|
23
24
|
},
|
|
24
25
|
"author": "rodney.vin@gmail.com",
|
|
25
26
|
"license": "Apache-2.0",
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@creejs/commons-lang": "
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"better-docs": "^2.7.3",
|
|
31
|
-
"jsdoc": "^4.0.4",
|
|
32
|
-
"log4js": "6.x"
|
|
28
|
+
"@creejs/commons-lang": "^2.0.0"
|
|
33
29
|
}
|
|
34
30
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export = ConsoleLogFactory;
|
|
2
|
+
/**
|
|
3
|
+
* Use Console as the native library
|
|
4
|
+
*/
|
|
5
|
+
declare class ConsoleLogFactory extends LogFactory {
|
|
6
|
+
/**
|
|
7
|
+
* the underlying "Console" Object.
|
|
8
|
+
* @returns {{}}
|
|
9
|
+
*/
|
|
10
|
+
get console(): {};
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current logging settings
|
|
13
|
+
* @returns {{level:number}} The logging settings object containing the current log level.
|
|
14
|
+
*/
|
|
15
|
+
get setting(): {
|
|
16
|
+
level: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
import LogFactory = require("../log-factory");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export = ConsoleProvider;
|
|
2
|
+
declare class ConsoleProvider extends Provider {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Provider instance.
|
|
5
|
+
* @param {Object} libraryModule - The library module to be used.
|
|
6
|
+
* @param {Object} setting - Configuration settings for the provider.
|
|
7
|
+
* @returns {ConsoleLogFactory} A new instance of ConsoleProvider.
|
|
8
|
+
* @override
|
|
9
|
+
*/
|
|
10
|
+
override createLogFactory(libraryModule: Object, setting: Object): ConsoleLogFactory;
|
|
11
|
+
}
|
|
12
|
+
import Provider = require("../provider");
|
|
13
|
+
import ConsoleLogFactory = require("./console-log-factory");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export = ConsoleLogger;
|
|
2
|
+
/**
|
|
3
|
+
* A Simple Implementation of the Logger interface that logs to the console.
|
|
4
|
+
*/
|
|
5
|
+
declare class ConsoleLogger extends Logger {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a ConsoleLogger instance.
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {string} name - The logger name.
|
|
10
|
+
* @param {*} nativeLogger - The native console object to use for logging.
|
|
11
|
+
* @param {number} level - The initial log level.
|
|
12
|
+
*/
|
|
13
|
+
constructor(name: string, nativeLogger: any, level: number);
|
|
14
|
+
/**
|
|
15
|
+
* @type {{error:function, warn:function, debug:function, log:function, info:function, trace:function}}
|
|
16
|
+
*/
|
|
17
|
+
console: {
|
|
18
|
+
error: Function;
|
|
19
|
+
warn: Function;
|
|
20
|
+
debug: Function;
|
|
21
|
+
log: Function;
|
|
22
|
+
info: Function;
|
|
23
|
+
trace: Function;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
import Logger = require("../logger");
|
package/types/index.d.ts
CHANGED
|
@@ -1,22 +1,68 @@
|
|
|
1
|
+
import Provider = require("./provider");
|
|
2
|
+
import LogFactory = require("./log-factory");
|
|
1
3
|
import Logger = require("./logger");
|
|
2
|
-
import
|
|
4
|
+
import LogLevel = require("./log-level");
|
|
5
|
+
import ProviderType = require("./provider-type");
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
6
|
-
* @
|
|
7
|
+
* Gets a logger instance for the specified logger name using the current provider.
|
|
8
|
+
* @param {string} loggerName - The name of the logger to retrieve.
|
|
9
|
+
* @returns {Logger} The logger instance.
|
|
10
|
+
* @throws {Error} If no default provider is set or if the current provider is not initialized.
|
|
7
11
|
*/
|
|
8
|
-
export function
|
|
9
|
-
/**
|
|
10
|
-
* Gets or creates a named logger instance with the specified log level.
|
|
11
|
-
* If a logger with the given name already exists, updates its log level if different.
|
|
12
|
-
* @param {string} name - The name identifier for the logger
|
|
13
|
-
* @param {'TRACE'|'DEBUG'|'INFO'|'WARN'|'ERROR'|'FATAL'|'OFF'|'trace'|'debug'|'info'|'warn'|'error'|'fatal'|'off'} [level='ERROR'] - The log level
|
|
14
|
-
* @returns {Logger} The logger instance for the given name
|
|
15
|
-
*/
|
|
16
|
-
export function getLogger(name: string, level?: "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL" | "OFF" | "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "off"): Logger;
|
|
12
|
+
export function getLogger(loggerName: string): Logger;
|
|
17
13
|
/**
|
|
18
14
|
* set Global logging level
|
|
19
15
|
* @param {'TRACE'|'DEBUG'|'INFO'|'WARN'|'ERROR'|'FATAL'|'OFF'|'trace'|'debug'|'info'|'warn'|'error'|'fatal'|'off'} level - The log level
|
|
20
16
|
*/
|
|
21
17
|
export function setLevel(level: "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL" | "OFF" | "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "off"): void;
|
|
22
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Set the provider using currently
|
|
20
|
+
* @param {string} typeName - The type name of the logging provider to use.
|
|
21
|
+
* @returns {void}
|
|
22
|
+
* @throws {Error} If the provider name is unknown.
|
|
23
|
+
*/
|
|
24
|
+
export function useProvider(typeName: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* configure provider to initialize its LogFactory
|
|
27
|
+
* 1. find the LogProvider Implementation of "typeName"
|
|
28
|
+
* * if type is not supported, throw error
|
|
29
|
+
* 2. use the nativeLib and setting to initialize the LogProvider
|
|
30
|
+
* 3. create a LogFactory via teh LogProvider
|
|
31
|
+
* @param {string} typeName - The type of logging provider to configure.
|
|
32
|
+
* @param {*} [nativeLib] - The native library to use for logging.
|
|
33
|
+
* @param {*} [setting] - Configuration settings for the logging provider.
|
|
34
|
+
* @throws {Error} If the typeName is not recognized.
|
|
35
|
+
*/
|
|
36
|
+
export function configureProvider(typeName: string, nativeLib?: any, setting?: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* Configures and immediately uses a logging provider with the given settings.
|
|
39
|
+
* @param {string} typeName - The type/name identifier for the provider.
|
|
40
|
+
* @param {*} nativeLib - The native library implementation to configure.
|
|
41
|
+
* @param {*} setting - Configuration settings for the provider.
|
|
42
|
+
*/
|
|
43
|
+
export function configureThenUseProvider(typeName: string, nativeLib: any, setting: any): void;
|
|
44
|
+
/**
|
|
45
|
+
* Add a type of Provider
|
|
46
|
+
*
|
|
47
|
+
* More:
|
|
48
|
+
* 1. A Provider is a Module
|
|
49
|
+
* 2. The module must include the following functions:
|
|
50
|
+
* 1. getType() - Returns the type name of the provider.
|
|
51
|
+
* 2. createLogFactory() - Creates a new LogFactory instance.
|
|
52
|
+
* @param {Provider} provider - Logging Library Module
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
export function addProvider(provider: Provider): void;
|
|
56
|
+
export function clearProviders(): void;
|
|
57
|
+
export function currentProvider(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Removes and returns the provider associated with the given type name.
|
|
60
|
+
* If no provider exists for the type name, the function returns undefined.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} typeName - The type name of the provider to remove.
|
|
63
|
+
* @returns {boolean} The removed provider, or undefined if not found.
|
|
64
|
+
*/
|
|
65
|
+
export function removeProvider(typeName: string): boolean;
|
|
66
|
+
import ConsoleProvider = require("./console");
|
|
67
|
+
import Log4jsProvider = require("./log4js");
|
|
68
|
+
export { Provider, LogFactory, Logger, LogLevel, ProviderType, useProvider as use, configureProvider as configure, configureThenUseProvider as configureThenUse, addProvider as add, currentProvider as current, removeProvider as remove, ConsoleProvider, Log4jsProvider };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* type name of current provider
|
|
3
|
+
* @type {string}
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export let currentProvider: string;
|
|
7
|
+
/**
|
|
8
|
+
* Global logging level
|
|
9
|
+
* @type {number}
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export let currentLevel: number;
|
|
13
|
+
/**
|
|
14
|
+
* The map of registered logging libraries
|
|
15
|
+
* @type {Map<string,Provider>}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export const type2Provider: Map<string, Provider>;
|
|
19
|
+
/**
|
|
20
|
+
* Created LogFactories Index with type name
|
|
21
|
+
* @type {Map<string, LogFactory>}
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const type2Factory: Map<string, LogFactory>;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a logging provider for the specified type.
|
|
27
|
+
* @param {string} typeName - The type identifier for the provider.
|
|
28
|
+
* @param {Provider} provider - The logging provider implementation.
|
|
29
|
+
* @returns {void}
|
|
30
|
+
* @alias module:LogConfig.addProvider
|
|
31
|
+
*/
|
|
32
|
+
export function addProvider(typeName: string, provider: Provider): void;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the logging provider for the specified type name.
|
|
35
|
+
* @param {string} typeName - The type name to look up in the provider map.
|
|
36
|
+
* @returns {Provider|undefined} The logging provider instance if found, otherwise undefined.
|
|
37
|
+
*/
|
|
38
|
+
export function getProvider(typeName: string): Provider | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Removes a logging provider of the specified type.
|
|
41
|
+
* @param {string} typeName - The type name of the provider to remove.
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
export function removeProvider(typeName: string): boolean;
|
|
45
|
+
export function clearProviders(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Returns an array of all registered factory types and intances.
|
|
48
|
+
* 1. Each entry is a [type, factory] pair
|
|
49
|
+
* @returns {Array<{0:string, 1:Provider}>} An array of factory entries.
|
|
50
|
+
*/
|
|
51
|
+
export function listProviders(): Array<{
|
|
52
|
+
0: string;
|
|
53
|
+
1: Provider;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Registers a log factory for a given type name.
|
|
57
|
+
* @param {string} typeName - The name of the log type to register.
|
|
58
|
+
* @param {LogFactory} logFactory - Factory function that creates a logger for the specified type.
|
|
59
|
+
*/
|
|
60
|
+
export function addFactory(typeName: string, logFactory: LogFactory): void;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the factory function associated with the given type name.
|
|
63
|
+
* @param {string} typeName - The name of the type to look up.
|
|
64
|
+
* @returns {LogFactory|undefined} The factory function for the specified type.
|
|
65
|
+
*/
|
|
66
|
+
export function getFactory(typeName: string): LogFactory | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Removes a factory of the given type from the type-to-factory mapping.
|
|
69
|
+
* @param {string} typeName - The name of the type whose factory should be removed.
|
|
70
|
+
* @returns {boolean}
|
|
71
|
+
*/
|
|
72
|
+
export function removeFactory(typeName: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Clears all registered factories from the type2Factory instance.
|
|
75
|
+
* This is typically used to reset the factory state during testing or teardown.
|
|
76
|
+
*/
|
|
77
|
+
export function clearFactories(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Returns an array of all registered factory types and intances.
|
|
80
|
+
* 1. Each entry is a [type, factory] pair
|
|
81
|
+
* @returns {Array<{0:string, 1:LogFactory}>} An array of factory entries.
|
|
82
|
+
*/
|
|
83
|
+
export function listFactories(): Array<{
|
|
84
|
+
0: string;
|
|
85
|
+
1: LogFactory;
|
|
86
|
+
}>;
|
|
87
|
+
export function clear(): void;
|
|
88
|
+
import Provider = require("./provider");
|
|
89
|
+
import LogFactory = require("./log-factory");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export = LogFactory;
|
|
2
|
+
/**
|
|
3
|
+
* @abstract
|
|
4
|
+
*/
|
|
5
|
+
declare class LogFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a value resembles a LogFactory by verifying it has required methods.
|
|
8
|
+
* @param {*} value - The value to check
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
static isLogFactoryLike(value: any): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Asserts that the given value is a valid LogFactory-Like object.
|
|
14
|
+
* @throws {Error} Throws an error if the value is not LogFactory-Like
|
|
15
|
+
* @param {*} value - The value to check.
|
|
16
|
+
*/
|
|
17
|
+
static assertLogFactoryLike(value: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new logging provider instance.
|
|
20
|
+
* @param {{}} libraryModule - the library module
|
|
21
|
+
* @param {{}} setting - Configuration settings for the provider
|
|
22
|
+
*/
|
|
23
|
+
constructor(libraryModule: {}, setting: {});
|
|
24
|
+
_libraryModule: {};
|
|
25
|
+
_setting: {};
|
|
26
|
+
get libraryModule(): {};
|
|
27
|
+
get setting(): {};
|
|
28
|
+
/**
|
|
29
|
+
* Initializes the logging provider.
|
|
30
|
+
* 1. Do nothing in the default implementation.
|
|
31
|
+
* 2. Override this method to initialize the provider.
|
|
32
|
+
* @returns {Promise<void>|void}
|
|
33
|
+
*/
|
|
34
|
+
init(): Promise<void> | void;
|
|
35
|
+
/**
|
|
36
|
+
* Update factory's Log Level
|
|
37
|
+
* 1. Only Provider knows how to update
|
|
38
|
+
* * update level in "setting", so the new created Logger will use the new level
|
|
39
|
+
* 2. called when users want to change global log level via CommonsLogging.setLevel()
|
|
40
|
+
* @param {number} level - The log level to set, see {@link LogLevel.Level}
|
|
41
|
+
* @returns {void}
|
|
42
|
+
* @throws {Error} Throws an error as this method is Not Impled Yet.
|
|
43
|
+
* @abstract
|
|
44
|
+
*/
|
|
45
|
+
setLevel(level: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new logger named with the "loggerName"
|
|
48
|
+
* @param {string} loggerName - The name to associate with the logger instance.
|
|
49
|
+
* @throws {Error} Throws an error indicating the method is Not Impled Yet yet.
|
|
50
|
+
* @returns {Logger} A new logger intance
|
|
51
|
+
* @abstract
|
|
52
|
+
*/
|
|
53
|
+
createLogger(loggerName: string): Logger;
|
|
54
|
+
}
|
|
55
|
+
import Logger = require("./logger");
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* *
|
|
3
|
+
*/
|
|
4
|
+
export type Name = string;
|
|
5
|
+
export namespace Name {
|
|
6
|
+
export { TRACE };
|
|
7
|
+
export { DEBUG };
|
|
8
|
+
export { INFO };
|
|
9
|
+
export { WARN };
|
|
10
|
+
export { ERROR };
|
|
11
|
+
export { FATAL };
|
|
12
|
+
export { OFF };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* *
|
|
16
|
+
*/
|
|
17
|
+
export type Level = number;
|
|
18
|
+
export namespace Level {
|
|
19
|
+
let OFF_1: number;
|
|
20
|
+
export { OFF_1 as OFF };
|
|
21
|
+
let FATAL_1: number;
|
|
22
|
+
export { FATAL_1 as FATAL };
|
|
23
|
+
let ERROR_1: number;
|
|
24
|
+
export { ERROR_1 as ERROR };
|
|
25
|
+
let WARN_1: number;
|
|
26
|
+
export { WARN_1 as WARN };
|
|
27
|
+
let INFO_1: number;
|
|
28
|
+
export { INFO_1 as INFO };
|
|
29
|
+
let DEBUG_1: number;
|
|
30
|
+
export { DEBUG_1 as DEBUG };
|
|
31
|
+
let TRACE_1: number;
|
|
32
|
+
export { TRACE_1 as TRACE };
|
|
33
|
+
export let ALL: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The default logging level (ERROR)
|
|
37
|
+
* @type {number}
|
|
38
|
+
* @memberof LogLevel
|
|
39
|
+
* @static
|
|
40
|
+
*/
|
|
41
|
+
export const DefaultLevel: number;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the given level is a valid log level.
|
|
44
|
+
* @param {number} level - The log level to check.
|
|
45
|
+
* @returns {boolean} True if the level is valid, false otherwise.
|
|
46
|
+
* @memberof LogLevel
|
|
47
|
+
* @static
|
|
48
|
+
*/
|
|
49
|
+
export function hasLevel(level: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the given level name exists in the Name enum/object.
|
|
52
|
+
* @param {string} levelName - The name of the log level to check.
|
|
53
|
+
* @returns {boolean} True if the level name exists, false otherwise.
|
|
54
|
+
* @memberof LogLevel
|
|
55
|
+
* @static
|
|
56
|
+
*/
|
|
57
|
+
export function hasName(levelName: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Validates that a given level is a number and falls within the valid range.
|
|
60
|
+
* @param {*} level - The log level to validate
|
|
61
|
+
* @throws {Error} If level is not a number or outside valid range (Level.OFF to Level.ALL)
|
|
62
|
+
* @memberof LogLevel
|
|
63
|
+
* @static
|
|
64
|
+
*/
|
|
65
|
+
export function assertLevel(level: any): void;
|
|
66
|
+
/**
|
|
67
|
+
* Converts a numeric logging level value to its corresponding name.
|
|
68
|
+
* @param {number} value - The numeric logging level value to convert.
|
|
69
|
+
* @returns {string|undefined} The name associated with the given logging level value, from {@link LogLevel.Name}.
|
|
70
|
+
* @memberof LogLevel
|
|
71
|
+
* @static
|
|
72
|
+
*/
|
|
73
|
+
export function value2Name(value: number): string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Converts a logging level name to its corresponding numeric value.
|
|
76
|
+
* @param {string} name - The name of the logging level.
|
|
77
|
+
* @returns {number|undefined} The numeric value of the logging level from {@link LogLevel.Level}, or undefined if name is not supported.
|
|
78
|
+
* @memberof LogLevel
|
|
79
|
+
* @static
|
|
80
|
+
*/
|
|
81
|
+
export function name2Value(name: string): number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* @namespace LogLevel
|
|
84
|
+
* @description Defines the logging levels and provides utilities for working with them.
|
|
85
|
+
*/
|
|
86
|
+
declare const TRACE: "TRACE";
|
|
87
|
+
declare const DEBUG: "DEBUG";
|
|
88
|
+
declare const INFO: "INFO";
|
|
89
|
+
declare const WARN: "WARN";
|
|
90
|
+
declare const ERROR: "ERROR";
|
|
91
|
+
declare const FATAL: "FATAL";
|
|
92
|
+
declare const OFF: "OFF";
|
|
93
|
+
export { Name as LevelName, Level as LevelValue };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export namespace appenders {
|
|
2
|
+
namespace out {
|
|
3
|
+
let type: string;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export namespace categories {
|
|
7
|
+
namespace _default {
|
|
8
|
+
let appenders_1: string[];
|
|
9
|
+
export { appenders_1 as appenders };
|
|
10
|
+
export let level: string;
|
|
11
|
+
}
|
|
12
|
+
export { _default as default };
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export = Log4jsFactory;
|
|
2
|
+
/**
|
|
3
|
+
* Use log4js as the logging provider.
|
|
4
|
+
*/
|
|
5
|
+
declare class Log4jsFactory extends LogFactory {
|
|
6
|
+
/**
|
|
7
|
+
* the log4js module instance.
|
|
8
|
+
* @returns {{}} The log4js module instance.
|
|
9
|
+
*/
|
|
10
|
+
get log4js(): {};
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the log4js provider by configuring it with the provided settings.
|
|
13
|
+
* @override
|
|
14
|
+
*/
|
|
15
|
+
override init(): void;
|
|
16
|
+
}
|
|
17
|
+
import LogFactory = require("../log-factory");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export = Log4jsLogger;
|
|
2
|
+
declare class Log4jsLogger extends Logger {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new ConsoleLogger instance.
|
|
5
|
+
* @constructor
|
|
6
|
+
* @param {string} name - The name of the logger.
|
|
7
|
+
* @param {*} nativeLogger - Log4js library
|
|
8
|
+
*/
|
|
9
|
+
constructor(name: string, nativeLogger: any);
|
|
10
|
+
_level: any;
|
|
11
|
+
_logger: any;
|
|
12
|
+
}
|
|
13
|
+
import Logger = require("../logger");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export = Log4jsProvider;
|
|
2
|
+
declare class Log4jsProvider extends Provider {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Provider instance.
|
|
5
|
+
* @param {*} libraryModule - The library module to be used.
|
|
6
|
+
* @param {*} setting - Configuration settings for the provider.
|
|
7
|
+
* @returns {Log4jsFactory} A new instance of Log4jsFactory.
|
|
8
|
+
* @override
|
|
9
|
+
*/
|
|
10
|
+
override createLogFactory(libraryModule: any, setting: any): Log4jsFactory;
|
|
11
|
+
}
|
|
12
|
+
import Provider = require("../provider");
|
|
13
|
+
import Log4jsFactory = require("./log4js-factory");
|
package/types/logger.d.ts
CHANGED
|
@@ -1,111 +1,174 @@
|
|
|
1
1
|
export = Logger;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Abstract Logger Class of All Logger
|
|
4
4
|
* @abstract
|
|
5
5
|
*/
|
|
6
6
|
declare class Logger {
|
|
7
7
|
/**
|
|
8
|
-
* Creates a new
|
|
8
|
+
* Creates a new Logger instance.
|
|
9
9
|
* @constructor
|
|
10
10
|
* @param {string} name - The name identifier for the logger
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
11
|
+
* @param {*} [nativeLogger]
|
|
12
|
+
* @param {number} [level] - The logging level, default is Level.ERROR=1
|
|
13
13
|
*/
|
|
14
|
-
constructor(name: string,
|
|
14
|
+
constructor(name: string, nativeLogger?: any, level?: number);
|
|
15
15
|
_name: string;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
_nativeLogger: any;
|
|
17
|
+
_level: number;
|
|
18
|
+
get nativeLogger(): any;
|
|
19
|
+
get level(): number;
|
|
18
20
|
/**
|
|
19
21
|
* Gets the name of the logger instance.
|
|
20
22
|
* @returns {string} The name of the logger.
|
|
21
23
|
*/
|
|
22
24
|
get name(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if FATAL level logging is enabled for this logger.
|
|
27
|
+
* @returns {boolean} True if FATAL level logging is enabled, false otherwise.
|
|
28
|
+
*/
|
|
23
29
|
get fatalEnabled(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if ERROR level logging is enabled for this logger.
|
|
32
|
+
* @returns {boolean} True if ERROR level logging is enabled, false otherwise.
|
|
33
|
+
*/
|
|
24
34
|
get errorEnabled(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if WARN level logging is enabled for this logger.
|
|
37
|
+
* @returns {boolean} True if WARN level logging is enabled, false otherwise.
|
|
38
|
+
*/
|
|
25
39
|
get warnEnabled(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if DEBUG level logging is enabled for this logger.
|
|
42
|
+
* @returns {boolean} True if DEBUG level logging is enabled, false otherwise.
|
|
43
|
+
*/
|
|
26
44
|
get debugEnabled(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if INFO level logging is enabled for this logger.
|
|
47
|
+
* @returns {boolean} True if INFO level logging is enabled, false otherwise.
|
|
48
|
+
*/
|
|
27
49
|
get infoEnabled(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if TRACE level logging is enabled for this logger.
|
|
52
|
+
* @returns {boolean} True if TRACE level logging is enabled, false otherwise.
|
|
53
|
+
*/
|
|
28
54
|
get traceEnabled(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* change log level for current logger instance.
|
|
57
|
+
* @param {number} level - new log level to set
|
|
58
|
+
* @throws {Error} Currently throws an error as this method is Not Impled Yet.
|
|
59
|
+
* @abstract
|
|
60
|
+
*/
|
|
61
|
+
setLevel(level: number): void;
|
|
29
62
|
/**
|
|
30
63
|
* Logs a fatal error message with timestamp and logger name.
|
|
31
64
|
* Only outputs if fatal logging is enabled for this logger instance.
|
|
32
65
|
* @param {...any} args - Arguments to log (will be space-separated)
|
|
33
66
|
*/
|
|
34
67
|
fatal(...args: any[]): void;
|
|
35
|
-
/**
|
|
36
|
-
* Override this method to implement fatal logging.
|
|
37
|
-
* @public
|
|
38
|
-
* @param {...*} args - Variable arguments
|
|
39
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
40
|
-
*/
|
|
41
|
-
public _fatal(...args: any[]): void;
|
|
42
68
|
/**
|
|
43
69
|
* Logs an error message to the console with timestamp and logger name.
|
|
44
70
|
* Only logs if error logging is enabled for this logger instance.
|
|
45
71
|
* @param {...any} args - Arguments to be logged as error message
|
|
46
72
|
*/
|
|
47
73
|
error(...args: any[]): void;
|
|
48
|
-
/**
|
|
49
|
-
* Override this method to implement error logging.
|
|
50
|
-
* @public
|
|
51
|
-
* @param {...*} args - Variable arguments
|
|
52
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
53
|
-
*/
|
|
54
|
-
public _error(...args: any[]): void;
|
|
55
74
|
/**
|
|
56
75
|
* Logs a warning message to the console if warn logging is enabled.
|
|
57
76
|
* @param {...any} args - The arguments to log as a warning message.
|
|
58
77
|
*/
|
|
59
78
|
warn(...args: any[]): void;
|
|
60
|
-
/**
|
|
61
|
-
* Override this method to implement warn logging.
|
|
62
|
-
* @public
|
|
63
|
-
* @param {...*} args - Variable arguments
|
|
64
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
65
|
-
*/
|
|
66
|
-
public _warn(...args: any[]): void;
|
|
67
79
|
/**
|
|
68
80
|
* Logs debug messages to console if debug mode is enabled.
|
|
69
81
|
* @param {...any} args - The data to be logged
|
|
70
82
|
*/
|
|
71
83
|
debug(...args: any[]): void;
|
|
72
|
-
/**
|
|
73
|
-
* Override this method to implement debug logging.
|
|
74
|
-
* @public
|
|
75
|
-
* @param {...*} args - Variable arguments
|
|
76
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
77
|
-
*/
|
|
78
|
-
public _debug(...args: any[]): void;
|
|
79
84
|
/**
|
|
80
85
|
* Logs an info message to the console with timestamp and logger name.
|
|
81
86
|
* @param {...any} args - The data to be logged. Accepts multiple arguments.
|
|
82
|
-
* @example
|
|
83
|
-
* logger.info('Service started', { port: 3000 });
|
|
84
87
|
*/
|
|
85
88
|
info(...args: any[]): void;
|
|
86
|
-
/**
|
|
87
|
-
* Override this method to implement info logging.
|
|
88
|
-
* @public
|
|
89
|
-
* @param {...*} args - Variable arguments
|
|
90
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
91
|
-
*/
|
|
92
|
-
public _info(...args: any[]): void;
|
|
93
89
|
/**
|
|
94
90
|
* Logs a trace message with timestamp and logger name if trace logging is enabled.
|
|
95
91
|
* @param {...any} args - Data to be logged as trace message.
|
|
96
92
|
*/
|
|
97
93
|
trace(...args: any[]): void;
|
|
98
94
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
101
|
-
* @param {...*} args - Variable arguments
|
|
102
|
-
* @throws {Error} Always throws "Not Implemented Yet" error
|
|
95
|
+
* Checks if FATAL level logging is enabled for this logger.
|
|
96
|
+
* @returns {boolean} True if FATAL level logging is enabled, false otherwise.
|
|
103
97
|
*/
|
|
104
|
-
public _trace(...args: any[]): void;
|
|
105
98
|
isFatalEnabled(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Checks if ERROR level logging is enabled for this logger.
|
|
101
|
+
* @returns {boolean} True if ERROR level logging is enabled, false otherwise.
|
|
102
|
+
*/
|
|
106
103
|
isErrorEnabled(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if WARN level logging is enabled for this logger.
|
|
106
|
+
* @returns {boolean} True if WARN level logging is enabled, false otherwise.
|
|
107
|
+
*/
|
|
107
108
|
isWarnEnabled(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Checks if DEBUG level logging is enabled for this logger.
|
|
111
|
+
* @returns {boolean} True if DEBUG level logging is enabled, false otherwise.
|
|
112
|
+
*/
|
|
108
113
|
isDebugEnabled(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if INFO level logging is enabled for this logger.
|
|
116
|
+
* @returns {boolean} True if INFO level logging is enabled, false otherwise.
|
|
117
|
+
*/
|
|
109
118
|
isInfoEnabled(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if TRACE level logging is enabled for this logger.
|
|
121
|
+
* @returns {boolean} True if TRACE level logging is enabled, false otherwise.
|
|
122
|
+
*/
|
|
110
123
|
isTraceEnabled(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Sets the logging level
|
|
126
|
+
* @param {number} level
|
|
127
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error.
|
|
128
|
+
* @protected
|
|
129
|
+
* @abstract
|
|
130
|
+
*/
|
|
131
|
+
protected _setLevel(level: number): void;
|
|
132
|
+
/**
|
|
133
|
+
* Override this method to implement fatal logging.
|
|
134
|
+
* @protected
|
|
135
|
+
* @param {...*} args - Variable arguments
|
|
136
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
137
|
+
*/
|
|
138
|
+
protected _fatal(...args: any[]): void;
|
|
139
|
+
/**
|
|
140
|
+
* Override this method to implement error logging.
|
|
141
|
+
* @protected
|
|
142
|
+
* @param {...*} args - Variable arguments
|
|
143
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
144
|
+
*/
|
|
145
|
+
protected _error(...args: any[]): void;
|
|
146
|
+
/**
|
|
147
|
+
* Override this method to implement warn logging.
|
|
148
|
+
* @protected
|
|
149
|
+
* @param {...*} args - Variable arguments
|
|
150
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
151
|
+
*/
|
|
152
|
+
protected _warn(...args: any[]): void;
|
|
153
|
+
/**
|
|
154
|
+
* Override this method to implement debug logging.
|
|
155
|
+
* @protected
|
|
156
|
+
* @param {...*} args - Variable arguments
|
|
157
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
158
|
+
*/
|
|
159
|
+
protected _debug(...args: any[]): void;
|
|
160
|
+
/**
|
|
161
|
+
* Override this method to implement info logging.
|
|
162
|
+
* @protected
|
|
163
|
+
* @param {...*} args - Variable arguments
|
|
164
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
165
|
+
*/
|
|
166
|
+
protected _info(...args: any[]): void;
|
|
167
|
+
/**
|
|
168
|
+
* Override this method to implement trace logging.
|
|
169
|
+
* @protected
|
|
170
|
+
* @param {...*} args - Variable arguments
|
|
171
|
+
* @throws {Error} Always throws "Not Impled Yet Yet" error
|
|
172
|
+
*/
|
|
173
|
+
protected _trace(...args: any[]): void;
|
|
111
174
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export = Provider;
|
|
2
|
+
/**
|
|
3
|
+
* A interface that All Provider module must export
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
6
|
+
declare class Provider {
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a value resembles a logging provider by verifying it has required methods.
|
|
9
|
+
* @param {*} value - The value to check
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
static isProviderLike(value: any): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Asserts that the given value is a valid provider-like object.
|
|
15
|
+
* @throws {Error} Throws an error if the value is not provider-like.
|
|
16
|
+
* @param {*} value - The value to check.
|
|
17
|
+
*/
|
|
18
|
+
static assertProviderLike(value: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* The Type Name of current Provider
|
|
21
|
+
* @return {String} The type of the provider.
|
|
22
|
+
*/
|
|
23
|
+
getType(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new LogFactory instance
|
|
26
|
+
* @param {*} [nativeLib] - The native library to use for logging.
|
|
27
|
+
* @param {*} [setting] - Configuration settings for the logging provider.
|
|
28
|
+
* @returns {LogFactory} A new instance of LogFactory.
|
|
29
|
+
*/
|
|
30
|
+
createLogFactory(nativeLib?: any, setting?: any): LogFactory;
|
|
31
|
+
}
|
|
32
|
+
import LogFactory = require("./log-factory");
|