@jeffchi/logger 1.0.6 → 1.0.7
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/cache.js +1 -2
- package/lib/index.js +5 -5
- package/lib/interface.d.ts +1 -0
- package/lib/utils/checkPlateform.js +2 -1
- package/package.json +1 -1
package/lib/cache.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.LogCache = void 0;
|
|
|
7
7
|
const checkPlateform_1 = require("./utils/checkPlateform");
|
|
8
8
|
const date_fns_1 = require("date-fns");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const noop_1 = __importDefault(require("./utils/noop"));
|
|
12
11
|
const type_1 = require("./utils/type");
|
|
13
12
|
/** 单例模式的缓存对像 */
|
|
@@ -62,7 +61,7 @@ class LogCache {
|
|
|
62
61
|
write = (0, lodash_1.debounce)((file) => this.flush(file), 1000);
|
|
63
62
|
/** 检查日志文件的路径,如果目录不存在,则创建,最好返回有效的日志文件,如果文件已存在,则追加日志数据 */
|
|
64
63
|
#checkFolder(output) {
|
|
65
|
-
const paths =
|
|
64
|
+
const paths = this.#fs?.dirname?.(output || this.defaultLogFile) || '';
|
|
66
65
|
const { existsSync, mkdirSync } = this.#fs || {};
|
|
67
66
|
if (!existsSync?.(paths)) {
|
|
68
67
|
mkdirSync?.(paths);
|
package/lib/index.js
CHANGED
|
@@ -14,31 +14,31 @@ const loggerWithTags = (tags, options) => {
|
|
|
14
14
|
const { env, outputFile, ...mergedOptions } = { ...defOptions_1.defOptions, ...(options || {}) };
|
|
15
15
|
const debug = (...rest) => {
|
|
16
16
|
const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.DEBUG, ...mergedOptions });
|
|
17
|
-
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.debug(
|
|
17
|
+
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.debug(...prefix, ...rest);
|
|
18
18
|
cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
|
|
19
19
|
};
|
|
20
20
|
const info = (...rest) => {
|
|
21
21
|
const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.INFO, ...mergedOptions });
|
|
22
|
-
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.info(
|
|
22
|
+
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.info(...prefix, ...rest);
|
|
23
23
|
cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
|
|
24
24
|
};
|
|
25
25
|
const log = (...rest) => {
|
|
26
26
|
const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, mergedOptions);
|
|
27
|
-
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.log(
|
|
27
|
+
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.log(...prefix, ...rest);
|
|
28
28
|
cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
|
|
29
29
|
};
|
|
30
30
|
const warn = (...rest) => {
|
|
31
31
|
const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.WARN, ...mergedOptions });
|
|
32
32
|
const { disableError } = mergedOptions;
|
|
33
33
|
const out = disableError ? console.debug : console.warn;
|
|
34
|
-
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(
|
|
34
|
+
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(...prefix, ...rest);
|
|
35
35
|
cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
|
|
36
36
|
};
|
|
37
37
|
const error = (msg, cause) => {
|
|
38
38
|
const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.ERROR, ...mergedOptions });
|
|
39
39
|
const { ignoreThrow, disableError } = mergedOptions;
|
|
40
40
|
const out = disableError ? console.debug : console.error;
|
|
41
|
-
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(
|
|
41
|
+
(0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(...prefix, msg);
|
|
42
42
|
cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [msg] }, outputFile);
|
|
43
43
|
if (!ignoreThrow) {
|
|
44
44
|
throw new Error(msg, { cause });
|
package/lib/interface.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ const checkPlatform = () => Promise.all([Promise.resolve().then(() => __importSt
|
|
|
33
33
|
if (!fs)
|
|
34
34
|
return null;
|
|
35
35
|
const { existsSync, mkdirSync, writeFile } = fs;
|
|
36
|
-
const { sep, resolve, join } = path;
|
|
36
|
+
const { sep, resolve, join, dirname } = path;
|
|
37
37
|
return {
|
|
38
38
|
existsSync,
|
|
39
39
|
mkdirSync,
|
|
@@ -41,6 +41,7 @@ const checkPlatform = () => Promise.all([Promise.resolve().then(() => __importSt
|
|
|
41
41
|
join,
|
|
42
42
|
sep,
|
|
43
43
|
resolve,
|
|
44
|
+
dirname,
|
|
44
45
|
};
|
|
45
46
|
});
|
|
46
47
|
exports.checkPlatform = checkPlatform;
|