@weapp-core/logger 3.1.0 → 3.1.1

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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import * as picocolors_types from 'picocolors/types';
2
- import { ConsolaInstance } from 'consola';
1
+ import { ConsolaInstance } from "consola";
2
+ import * as picocolors_types0 from "picocolors/types";
3
3
 
4
+ //#region src/index.d.ts
4
5
  /**
5
6
  * @description 日志类型
6
7
  */
@@ -12,27 +13,27 @@ type LogLevel = LogType | 'silent';
12
13
  /**
13
14
  * @description 终端文本染色工具,基于 picocolors。
14
15
  */
15
- declare const colors: picocolors_types.Colors & {
16
- createColors: (enabled?: boolean) => picocolors_types.Colors;
16
+ declare const colors: picocolors_types0.Colors & {
17
+ createColors: (enabled?: boolean) => picocolors_types0.Colors;
17
18
  };
18
19
  interface LoggerConfig {
19
- /**
20
- * @description 全局日志级别
21
- * @example
22
- * level: 'info'
23
- */
24
- level?: LogLevel;
25
- /**
26
- * @description 按 tag 覆盖日志级别
27
- * @example
28
- * tags: { build: 'warn', npm: 'silent' }
29
- */
30
- tags?: Record<string, LogLevel | undefined>;
20
+ /**
21
+ * @description 全局日志级别
22
+ * @example
23
+ * level: 'info'
24
+ */
25
+ level?: LogLevel;
26
+ /**
27
+ * @description 按 tag 覆盖日志级别
28
+ * @example
29
+ * tags: { build: 'warn', npm: 'silent' }
30
+ */
31
+ tags?: Record<string, LogLevel | undefined>;
31
32
  }
32
33
  /**
33
34
  * @description 设置全局 logger 配置
34
35
  */
35
36
  declare function configureLogger(config?: LoggerConfig): void;
36
37
  declare const logger: ConsolaInstance;
37
-
38
- export { type LogLevel, type LogType, type LoggerConfig, colors, configureLogger, logger as default };
38
+ //#endregion
39
+ export { LogLevel, LogType, LoggerConfig, colors, configureLogger, logger as default };
package/dist/index.js CHANGED
@@ -1,82 +1,68 @@
1
- // src/index.ts
2
1
  import { createConsola } from "consola";
3
2
  import picocolors from "picocolors";
4
- var colors = picocolors;
5
- var baseLogger = createConsola();
6
- var levelRank = {
7
- silent: -1,
8
- error: 0,
9
- warn: 1,
10
- info: 2
3
+ //#region src/index.ts
4
+ /**
5
+ * @description 终端文本染色工具,基于 picocolors。
6
+ */
7
+ const colors = picocolors;
8
+ const baseLogger = createConsola();
9
+ const levelRank = {
10
+ silent: -1,
11
+ error: 0,
12
+ warn: 1,
13
+ info: 2
11
14
  };
12
- var typeLevel = {
13
- fatal: 0,
14
- error: 0,
15
- warn: 1,
16
- log: 2,
17
- info: 2,
18
- success: 2,
19
- fail: 2,
20
- ready: 2,
21
- start: 2,
22
- box: 2,
23
- debug: 2,
24
- trace: 2
15
+ const typeLevel = {
16
+ fatal: 0,
17
+ error: 0,
18
+ warn: 1,
19
+ log: 2,
20
+ info: 2,
21
+ success: 2,
22
+ fail: 2,
23
+ ready: 2,
24
+ start: 2,
25
+ box: 2,
26
+ debug: 2,
27
+ trace: 2
25
28
  };
26
- var defaultLoggerConfig = {
27
- level: "info",
28
- tags: {}
29
+ const defaultLoggerConfig = {
30
+ level: "info",
31
+ tags: {}
29
32
  };
30
- var loggerConfig = { ...defaultLoggerConfig };
33
+ let loggerConfig = { ...defaultLoggerConfig };
34
+ /**
35
+ * @description 设置全局 logger 配置
36
+ */
31
37
  function configureLogger(config = {}) {
32
- loggerConfig = {
33
- level: config.level ?? defaultLoggerConfig.level,
34
- tags: config.tags ?? defaultLoggerConfig.tags
35
- };
38
+ loggerConfig = {
39
+ level: config.level ?? defaultLoggerConfig.level,
40
+ tags: config.tags ?? defaultLoggerConfig.tags
41
+ };
36
42
  }
37
43
  function resolveLogLevel(tag) {
38
- if (tag && loggerConfig.tags[tag]) {
39
- return loggerConfig.tags[tag];
40
- }
41
- return loggerConfig.level;
44
+ if (tag && loggerConfig.tags[tag]) return loggerConfig.tags[tag];
45
+ return loggerConfig.level;
42
46
  }
43
47
  function shouldLog(tag, type) {
44
- const level = resolveLogLevel(tag);
45
- if (level === "silent") {
46
- return false;
47
- }
48
- const requiredLevel = typeLevel[type] ?? levelRank.info;
49
- return levelRank[level] >= requiredLevel;
48
+ const level = resolveLogLevel(tag);
49
+ if (level === "silent") return false;
50
+ const requiredLevel = typeLevel[type] ?? levelRank.info;
51
+ return levelRank[level] >= requiredLevel;
50
52
  }
51
53
  function createLogger(tag) {
52
- const target = tag ? baseLogger.withTag(tag) : baseLogger;
53
- return new Proxy(target, {
54
- get(targetLogger, prop, receiver) {
55
- if (prop === "withTag" || prop === "withScope") {
56
- return (nextTag) => createLogger(nextTag);
57
- }
58
- if (typeof prop !== "string") {
59
- return Reflect.get(targetLogger, prop, receiver);
60
- }
61
- const value = Reflect.get(targetLogger, prop, receiver);
62
- if (typeof value === "function" && prop in typeLevel) {
63
- return (...args) => {
64
- if (shouldLog(tag, prop)) {
65
- return value.apply(targetLogger, args);
66
- }
67
- };
68
- }
69
- if (typeof value === "function") {
70
- return value.bind(targetLogger);
71
- }
72
- return value;
73
- }
74
- });
54
+ const target = tag ? baseLogger.withTag(tag) : baseLogger;
55
+ return new Proxy(target, { get(targetLogger, prop, receiver) {
56
+ if (prop === "withTag" || prop === "withScope") return (nextTag) => createLogger(nextTag);
57
+ if (typeof prop !== "string") return Reflect.get(targetLogger, prop, receiver);
58
+ const value = Reflect.get(targetLogger, prop, receiver);
59
+ if (typeof value === "function" && prop in typeLevel) return (...args) => {
60
+ if (shouldLog(tag, prop)) return value.apply(targetLogger, args);
61
+ };
62
+ if (typeof value === "function") return value.bind(targetLogger);
63
+ return value;
64
+ } });
75
65
  }
76
- var logger = createLogger();
77
- var index_default = logger;
78
- export {
79
- colors,
80
- configureLogger,
81
- index_default as default
82
- };
66
+ const logger = createLogger();
67
+ //#endregion
68
+ export { colors, configureLogger, logger as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/logger",
3
3
  "type": "module",
4
- "version": "3.1.0",
4
+ "version": "3.1.1",
5
5
  "description": "@weapp-core/logger",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -43,10 +43,11 @@
43
43
  "picocolors": "^1.1.1"
44
44
  },
45
45
  "scripts": {
46
- "dev": "tsup --watch --sourcemap",
47
- "build": "tsup",
46
+ "dev": "tsdown -w --sourcemap",
47
+ "build": "tsdown",
48
48
  "test": "vitest run",
49
49
  "test:dev": "vitest",
50
+ "typecheck": "tsc --noEmit",
50
51
  "release": "pnpm publish",
51
52
  "lint": "eslint .",
52
53
  "lint:fix": "eslint . --fix",