@powerlines/core 0.44.0 → 0.44.2

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.
Files changed (73) hide show
  1. package/dist/constants/index.cjs +2 -2
  2. package/dist/constants/index.mjs +2 -2
  3. package/dist/constants/log-level.cjs +2 -2
  4. package/dist/constants/log-level.d.cts +2 -2
  5. package/dist/constants/log-level.d.mts +2 -2
  6. package/dist/constants/log-level.mjs +2 -2
  7. package/dist/constants/log-level.mjs.map +1 -1
  8. package/dist/index.cjs +7 -10
  9. package/dist/index.d.cts +3 -4
  10. package/dist/index.d.mts +3 -4
  11. package/dist/index.mjs +4 -4
  12. package/dist/lib/index.cjs +1 -7
  13. package/dist/lib/index.d.cts +1 -2
  14. package/dist/lib/index.d.mts +1 -2
  15. package/dist/lib/index.mjs +2 -3
  16. package/dist/lib/unplugin/plugin.cjs +9 -11
  17. package/dist/lib/unplugin/plugin.d.cts.map +1 -1
  18. package/dist/lib/unplugin/plugin.d.mts.map +1 -1
  19. package/dist/lib/unplugin/plugin.mjs +9 -11
  20. package/dist/lib/unplugin/plugin.mjs.map +1 -1
  21. package/dist/lib/utilities/index.cjs +1 -1
  22. package/dist/lib/utilities/index.mjs +1 -1
  23. package/dist/lib/utilities/write-file.d.cts +1 -1
  24. package/dist/lib/utilities/write-file.d.mts +1 -1
  25. package/dist/lib/utilities/write-file.mjs.map +1 -1
  26. package/dist/plugin-utils/index.cjs +15 -2
  27. package/dist/plugin-utils/index.d.cts +2 -2
  28. package/dist/plugin-utils/index.d.mts +2 -2
  29. package/dist/plugin-utils/index.mjs +3 -3
  30. package/dist/plugin-utils/logging.cjs +421 -4
  31. package/dist/plugin-utils/logging.d.cts +77 -3
  32. package/dist/plugin-utils/logging.d.cts.map +1 -1
  33. package/dist/plugin-utils/logging.d.mts +77 -3
  34. package/dist/plugin-utils/logging.d.mts.map +1 -1
  35. package/dist/plugin-utils/logging.mjs +407 -4
  36. package/dist/plugin-utils/logging.mjs.map +1 -1
  37. package/dist/plugin-utils/paths.cjs +1 -1
  38. package/dist/plugin-utils/paths.mjs +1 -1
  39. package/dist/plugin-utils/paths.mjs.map +1 -1
  40. package/dist/types/config.d.cts +11 -4
  41. package/dist/types/config.d.cts.map +1 -1
  42. package/dist/types/config.d.mts +11 -4
  43. package/dist/types/config.d.mts.map +1 -1
  44. package/dist/types/context.d.cts +17 -28
  45. package/dist/types/context.d.cts.map +1 -1
  46. package/dist/types/context.d.mts +17 -28
  47. package/dist/types/context.d.mts.map +1 -1
  48. package/dist/types/index.cjs +1 -0
  49. package/dist/types/index.d.cts +2 -2
  50. package/dist/types/index.d.mts +2 -2
  51. package/dist/types/index.mjs +3 -0
  52. package/dist/types/logging.cjs +48 -0
  53. package/dist/types/logging.d.cts +175 -0
  54. package/dist/types/logging.d.cts.map +1 -0
  55. package/dist/types/logging.d.mts +175 -0
  56. package/dist/types/logging.d.mts.map +1 -0
  57. package/dist/types/logging.mjs +45 -0
  58. package/dist/types/logging.mjs.map +1 -0
  59. package/package.json +74 -442
  60. package/dist/lib/logger.cjs +0 -106
  61. package/dist/lib/logger.d.cts +0 -42
  62. package/dist/lib/logger.d.cts.map +0 -1
  63. package/dist/lib/logger.d.mts +0 -42
  64. package/dist/lib/logger.d.mts.map +0 -1
  65. package/dist/lib/logger.mjs +0 -100
  66. package/dist/lib/logger.mjs.map +0 -1
  67. package/dist/types/log.cjs +0 -26
  68. package/dist/types/log.d.cts +0 -90
  69. package/dist/types/log.d.cts.map +0 -1
  70. package/dist/types/log.d.mts +0 -90
  71. package/dist/types/log.d.mts.map +0 -1
  72. package/dist/types/log.mjs +0 -25
  73. package/dist/types/log.mjs.map +0 -1
@@ -1,6 +1,7 @@
1
- import { LogLevelResolvedConfig, LogLevelUserConfig } from "../types/log.cjs";
1
+ import { CustomLogger, LogCategory, LogFn, LogFnOptions, LogLevel, LogLevelResolvedConfig, LogLevelUserConfig, LogMeta, Logger, LoggerMessage, LoggerOptions } from "../types/logging.cjs";
2
2
  import { UnresolvedContext } from "../types/context.cjs";
3
3
  import { Mode } from "../types/config.cjs";
4
+
4
5
  //#region src/plugin-utils/logging.d.ts
5
6
  /**
6
7
  * Determines if the provided log level is considered verbose (debug or trace).
@@ -23,7 +24,80 @@ declare function isVerbose(context: UnresolvedContext): boolean;
23
24
  * @param mode - The current mode of the application (e.g., "development", "test", "production"), which determines the default log levels.
24
25
  * @returns A LogLevelResolvedConfig object specifying the log level for each log category.
25
26
  */
26
- declare function resolveLogLevel(logLevel: LogLevelUserConfig, mode?: Mode): LogLevelResolvedConfig;
27
+ declare function resolveLogLevel(logLevel?: LogLevelUserConfig, mode?: Mode): LogLevelResolvedConfig;
28
+ /**
29
+ * Generate a consistent color based on the input text.
30
+ *
31
+ * @param text - The input text to generate the color from.
32
+ * @return A hexadecimal color string.
33
+ */
34
+ declare const getTextColor: (text: string) => string;
35
+ /**
36
+ * Generate a consistent color based on the input text.
37
+ *
38
+ * @param text - The input text to generate the color from.
39
+ * @return A hexadecimal color string.
40
+ */
41
+ declare const colorText: (text: string) => string;
42
+ /**
43
+ * Generate a consistent color based on the input text.
44
+ *
45
+ * @param text - The input text to generate the color from.
46
+ * @return A hexadecimal color string.
47
+ */
48
+ declare const colorBackground: (text: string) => string;
49
+ declare const consoleLog: (meta: LogMeta, ...args: string[]) => void;
50
+ declare function isValidLogLevel(logLevel: LogLevel, type: LogLevel): boolean;
51
+ declare function isValidLogLevelConfig(type: LogLevel, logLevel: LogLevelResolvedConfig, category?: LogCategory): boolean;
52
+ /**
53
+ * Create a logging function with a specific name and options.
54
+ *
55
+ * @param name - The name of the logging function.
56
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
57
+ * @returns A logging function.
58
+ */
59
+ declare const createLogFn: (name: string, options: LogFnOptions) => LogFn;
60
+ /**
61
+ * Create a logging function with a specific name and options.
62
+ *
63
+ * @param logger - The original logger to wrap with the custom logger.
64
+ * @param secondaryLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
65
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
66
+ */
67
+ declare const withLogger: (logger: Logger, secondaryLogger: Logger) => Logger;
68
+ /**
69
+ * Create a logging function with a specific name and options.
70
+ *
71
+ * @param logger - The original logger to wrap with the custom logger.
72
+ * @param customLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
73
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
74
+ */
75
+ declare const withCustomLogger: (logger: Logger, customLogger: CustomLogger) => Logger;
76
+ declare const consoleLogger: (type: LogLevel, message: string | LoggerMessage) => void;
77
+ /**
78
+ * Create a logging function with a specific name and options.
79
+ *
80
+ * @param name - The name of the logging function.
81
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
82
+ * @returns A logging function.
83
+ */
84
+ declare const createLogger: (name: string, options: LoggerOptions, callback?: (type: LogLevel, message: string | LoggerMessage) => void) => Logger;
85
+ /**
86
+ * Extend a logging function with a specific name, adding a colored badge to the log output.
87
+ *
88
+ * @param logFn - The original logging function to extend.
89
+ * @param options - The overlay metadata to use for the badge in the log output.
90
+ * @returns A new logging function that includes the badge in its output.
91
+ */
92
+ declare const extendLogFn: (logFn: LogFn, options: LogFnOptions) => LogFn;
93
+ /**
94
+ * Extend a logger with a specific name and options, adding a colored badge to the log output for each log message generated by the logger.
95
+ *
96
+ * @param logger - The original logger to extend.
97
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the extended logger.
98
+ * @returns A new logger that includes the badge in its output for each log message.
99
+ */
100
+ declare const extendLogger: (logger: Logger, options: LoggerOptions) => Logger;
27
101
  //#endregion
28
- export { isVerbose, resolveLogLevel };
102
+ export { colorBackground, colorText, consoleLog, consoleLogger, createLogFn, createLogger, extendLogFn, extendLogger, getTextColor, isValidLogLevel, isValidLogLevelConfig, isVerbose, resolveLogLevel, withCustomLogger, withLogger };
29
103
  //# sourceMappingURL=logging.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logging.d.cts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;;;;AAoCA;;iBAAgB,SAAA,CAAU,QAAA;;;AAQ1B;;;;iBAAgB,SAAA,CAAU,OAAA,EAAS,iBAAA;AAyBnC;;;;;;;AAAA,iBAAgB,eAAA,CACd,QAAA,EAAU,kBAAA,EACV,IAAA,GAAO,IAAA,GACN,sBAAA"}
1
+ {"version":3,"file":"logging.d.cts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;;AA2DA;;;;;iBAAgB,SAAA,CAAU,QAAA;;;;;AAiC1B;;iBAzBgB,SAAA,CAAU,OAAA,EAAS,iBAAA;;;;;;;;iBAyBnB,eAAA,CACd,QAAA,GAAW,kBAAA,EACX,IAAA,GAAO,IAAA,GACN,sBAAA;;;;;AA2FH;;cAAa,YAAA,GAAgB,IAAA;;;AAiB7B;;;;cAAa,SAAA,GAAa,IAAA;AAY1B;;;;;AAMA;AANA,cAAa,eAAA,GAAmB,IAAA;AAAA,cAMnB,UAAA,GAAc,IAAA,EAAM,OAAA,KAAY,IAAA;AAAA,iBA2B7B,eAAA,CAAgB,QAAA,EAAU,QAAA,EAAU,IAAA,EAAM,QAAA;AAAA,iBAQ1C,qBAAA,CACd,IAAA,EAAM,QAAA,EACN,QAAA,EAAU,sBAAA,EACV,QAAA,GAAU,WAAA;;;;;AAXZ;;;cAuBa,WAAA,GAAe,IAAA,UAAc,OAAA,EAAS,YAAA,KAAe,KAAA;;;;;;;AAflE;cAoJa,UAAA,GAAc,MAAA,EAAQ,MAAA,EAAQ,eAAA,EAAiB,MAAA,KAAS,MAAA;;;;;;;;cAuFxD,gBAAA,GACX,MAAA,EAAQ,MAAA,EACR,YAAA,EAAc,YAAA,KACb,MAAA;AAAA,cAoEU,aAAA,GACX,IAAA,EAAM,QAAA,EACN,OAAA,WAAkB,aAAA;;;;;;AArSpB;;cAgUa,YAAA,GACX,IAAA,UACA,OAAA,EAAS,aAAA,EACT,QAAA,IACE,IAAA,EAAM,QAAA,EACN,OAAA,WAAkB,aAAA,cAEnB,MAAA;;;;;;;;cAuDU,WAAA,GAAe,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,YAAA,KAAe,KAAA;;;;;;;;cAsBrD,YAAA,GACX,MAAA,EAAQ,MAAA,EACR,OAAA,EAAS,aAAA,KACR,MAAA"}
@@ -1,6 +1,7 @@
1
- import { LogLevelResolvedConfig, LogLevelUserConfig } from "../types/log.mjs";
1
+ import { CustomLogger, LogCategory, LogFn, LogFnOptions, LogLevel, LogLevelResolvedConfig, LogLevelUserConfig, LogMeta, Logger, LoggerMessage, LoggerOptions } from "../types/logging.mjs";
2
2
  import { UnresolvedContext } from "../types/context.mjs";
3
3
  import { Mode } from "../types/config.mjs";
4
+
4
5
  //#region src/plugin-utils/logging.d.ts
5
6
  /**
6
7
  * Determines if the provided log level is considered verbose (debug or trace).
@@ -23,7 +24,80 @@ declare function isVerbose(context: UnresolvedContext): boolean;
23
24
  * @param mode - The current mode of the application (e.g., "development", "test", "production"), which determines the default log levels.
24
25
  * @returns A LogLevelResolvedConfig object specifying the log level for each log category.
25
26
  */
26
- declare function resolveLogLevel(logLevel: LogLevelUserConfig, mode?: Mode): LogLevelResolvedConfig;
27
+ declare function resolveLogLevel(logLevel?: LogLevelUserConfig, mode?: Mode): LogLevelResolvedConfig;
28
+ /**
29
+ * Generate a consistent color based on the input text.
30
+ *
31
+ * @param text - The input text to generate the color from.
32
+ * @return A hexadecimal color string.
33
+ */
34
+ declare const getTextColor: (text: string) => string;
35
+ /**
36
+ * Generate a consistent color based on the input text.
37
+ *
38
+ * @param text - The input text to generate the color from.
39
+ * @return A hexadecimal color string.
40
+ */
41
+ declare const colorText: (text: string) => string;
42
+ /**
43
+ * Generate a consistent color based on the input text.
44
+ *
45
+ * @param text - The input text to generate the color from.
46
+ * @return A hexadecimal color string.
47
+ */
48
+ declare const colorBackground: (text: string) => string;
49
+ declare const consoleLog: (meta: LogMeta, ...args: string[]) => void;
50
+ declare function isValidLogLevel(logLevel: LogLevel, type: LogLevel): boolean;
51
+ declare function isValidLogLevelConfig(type: LogLevel, logLevel: LogLevelResolvedConfig, category?: LogCategory): boolean;
52
+ /**
53
+ * Create a logging function with a specific name and options.
54
+ *
55
+ * @param name - The name of the logging function.
56
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
57
+ * @returns A logging function.
58
+ */
59
+ declare const createLogFn: (name: string, options: LogFnOptions) => LogFn;
60
+ /**
61
+ * Create a logging function with a specific name and options.
62
+ *
63
+ * @param logger - The original logger to wrap with the custom logger.
64
+ * @param secondaryLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
65
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
66
+ */
67
+ declare const withLogger: (logger: Logger, secondaryLogger: Logger) => Logger;
68
+ /**
69
+ * Create a logging function with a specific name and options.
70
+ *
71
+ * @param logger - The original logger to wrap with the custom logger.
72
+ * @param customLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
73
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
74
+ */
75
+ declare const withCustomLogger: (logger: Logger, customLogger: CustomLogger) => Logger;
76
+ declare const consoleLogger: (type: LogLevel, message: string | LoggerMessage) => void;
77
+ /**
78
+ * Create a logging function with a specific name and options.
79
+ *
80
+ * @param name - The name of the logging function.
81
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
82
+ * @returns A logging function.
83
+ */
84
+ declare const createLogger: (name: string, options: LoggerOptions, callback?: (type: LogLevel, message: string | LoggerMessage) => void) => Logger;
85
+ /**
86
+ * Extend a logging function with a specific name, adding a colored badge to the log output.
87
+ *
88
+ * @param logFn - The original logging function to extend.
89
+ * @param options - The overlay metadata to use for the badge in the log output.
90
+ * @returns A new logging function that includes the badge in its output.
91
+ */
92
+ declare const extendLogFn: (logFn: LogFn, options: LogFnOptions) => LogFn;
93
+ /**
94
+ * Extend a logger with a specific name and options, adding a colored badge to the log output for each log message generated by the logger.
95
+ *
96
+ * @param logger - The original logger to extend.
97
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the extended logger.
98
+ * @returns A new logger that includes the badge in its output for each log message.
99
+ */
100
+ declare const extendLogger: (logger: Logger, options: LoggerOptions) => Logger;
27
101
  //#endregion
28
- export { isVerbose, resolveLogLevel };
102
+ export { colorBackground, colorText, consoleLog, consoleLogger, createLogFn, createLogger, extendLogFn, extendLogger, getTextColor, isValidLogLevel, isValidLogLevelConfig, isVerbose, resolveLogLevel, withCustomLogger, withLogger };
29
103
  //# sourceMappingURL=logging.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logging.d.mts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;;;;AAoCA;;iBAAgB,SAAA,CAAU,QAAA;;;AAQ1B;;;;iBAAgB,SAAA,CAAU,OAAA,EAAS,iBAAA;AAyBnC;;;;;;;AAAA,iBAAgB,eAAA,CACd,QAAA,EAAU,kBAAA,EACV,IAAA,GAAO,IAAA,GACN,sBAAA"}
1
+ {"version":3,"file":"logging.d.mts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;;AA2DA;;;;;iBAAgB,SAAA,CAAU,QAAA;;;;;AAiC1B;;iBAzBgB,SAAA,CAAU,OAAA,EAAS,iBAAA;;;;;;;;iBAyBnB,eAAA,CACd,QAAA,GAAW,kBAAA,EACX,IAAA,GAAO,IAAA,GACN,sBAAA;;;;;AA2FH;;cAAa,YAAA,GAAgB,IAAA;;;AAiB7B;;;;cAAa,SAAA,GAAa,IAAA;AAY1B;;;;;AAMA;AANA,cAAa,eAAA,GAAmB,IAAA;AAAA,cAMnB,UAAA,GAAc,IAAA,EAAM,OAAA,KAAY,IAAA;AAAA,iBA2B7B,eAAA,CAAgB,QAAA,EAAU,QAAA,EAAU,IAAA,EAAM,QAAA;AAAA,iBAQ1C,qBAAA,CACd,IAAA,EAAM,QAAA,EACN,QAAA,EAAU,sBAAA,EACV,QAAA,GAAU,WAAA;;;;;AAXZ;;;cAuBa,WAAA,GAAe,IAAA,UAAc,OAAA,EAAS,YAAA,KAAe,KAAA;;;;;;;AAflE;cAoJa,UAAA,GAAc,MAAA,EAAQ,MAAA,EAAQ,eAAA,EAAiB,MAAA,KAAS,MAAA;;;;;;;;cAuFxD,gBAAA,GACX,MAAA,EAAQ,MAAA,EACR,YAAA,EAAc,YAAA,KACb,MAAA;AAAA,cAoEU,aAAA,GACX,IAAA,EAAM,QAAA,EACN,OAAA,WAAkB,aAAA;;;;;;AArSpB;;cAgUa,YAAA,GACX,IAAA,UACA,OAAA,EAAS,aAAA,EACT,QAAA,IACE,IAAA,EAAM,QAAA,EACN,OAAA,WAAkB,aAAA,cAEnB,MAAA;;;;;;;;cAuDU,WAAA,GAAe,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,YAAA,KAAe,KAAA;;;;;;;;cAsBrD,YAAA,GACX,MAAA,EAAQ,MAAA,EACR,OAAA,EAAS,aAAA,KACR,MAAA"}
@@ -1,8 +1,16 @@
1
+ import { LOG_LEVELS, LogCategories, LogLevels } from "../types/logging.mjs";
2
+ import { DEFAULT_ENVIRONMENT } from "../constants/environments.mjs";
1
3
  import { DEFAULT_DEVELOPMENT_LOG_LEVEL, DEFAULT_PRODUCTION_LOG_LEVEL, DEFAULT_TEST_LOG_LEVEL } from "../constants/log-level.mjs";
2
4
  import { isSetObject } from "@stryke/type-checks/is-set-object";
3
5
  import { defu as defu$1 } from "defu";
4
6
  import { isSetString } from "@stryke/type-checks/is-set-string";
5
7
  import { isString } from "@stryke/type-checks/is-string";
8
+ import { kebabCase } from "@stryke/string-format/kebab-case";
9
+ import { titleCase } from "@stryke/string-format/title-case";
10
+ import { getLogFn, getLogLevel } from "@storm-software/config-tools/logger";
11
+ import { getColor } from "@storm-software/config-tools/utilities/colors";
12
+ import { uuid } from "@stryke/unique-id/uuid";
13
+ import chalk from "chalk";
6
14
 
7
15
  //#region src/plugin-utils/logging.ts
8
16
  /**
@@ -32,7 +40,8 @@ function resolveLogLevel(logLevel, mode) {
32
40
  hooks: "trace",
33
41
  env: "trace",
34
42
  ipc: "trace",
35
- config: "trace"
43
+ config: "trace",
44
+ babel: "trace"
36
45
  };
37
46
  else if (logLevel === "silent") return {
38
47
  general: "silent",
@@ -43,7 +52,8 @@ function resolveLogLevel(logLevel, mode) {
43
52
  hooks: "silent",
44
53
  env: "silent",
45
54
  ipc: "silent",
46
- config: "silent"
55
+ config: "silent",
56
+ babel: "silent"
47
57
  };
48
58
  let defaultLogLevel;
49
59
  if (mode === "development") defaultLogLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;
@@ -58,12 +68,405 @@ function resolveLogLevel(logLevel, mode) {
58
68
  hooks: logLevel,
59
69
  env: defaultLogLevel.env,
60
70
  ipc: defaultLogLevel.ipc,
61
- config: defaultLogLevel.config
71
+ config: defaultLogLevel.config,
72
+ babel: logLevel
62
73
  };
63
74
  else if (isSetObject(logLevel)) return defu$1(logLevel, defaultLogLevel);
64
75
  return defaultLogLevel;
65
76
  }
77
+ const BADGE_COLORS = [
78
+ "#00A0DD",
79
+ "#6FCE4E",
80
+ "#FBBF24",
81
+ "#F43F5E",
82
+ "#3B82F6",
83
+ "#A855F7",
84
+ "#469592",
85
+ "#288EDF",
86
+ "#D8B4FE",
87
+ "#10B981",
88
+ "#EF4444",
89
+ "#F0EC56",
90
+ "#F472B6",
91
+ "#22D3EE",
92
+ "#EAB308",
93
+ "#84CC16",
94
+ "#F87171",
95
+ "#0EA5E9",
96
+ "#D946EF",
97
+ "#FACC15",
98
+ "#34D399",
99
+ "#8B5CF6"
100
+ ];
101
+ const BRAND_COLOR = getColor("brand");
102
+ /**
103
+ * Generate a consistent color based on the input text.
104
+ *
105
+ * @param text - The input text to generate the color from.
106
+ * @return A hexadecimal color string.
107
+ */
108
+ const getTextColor = (text) => {
109
+ return BADGE_COLORS[text.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0];
110
+ };
111
+ /**
112
+ * Generate a consistent color based on the input text.
113
+ *
114
+ * @param text - The input text to generate the color from.
115
+ * @return A hexadecimal color string.
116
+ */
117
+ const colorText = (text) => {
118
+ const title = titleCase(text);
119
+ return chalk.hex(getTextColor(title))(title);
120
+ };
121
+ /**
122
+ * Generate a consistent color based on the input text.
123
+ *
124
+ * @param text - The input text to generate the color from.
125
+ * @return A hexadecimal color string.
126
+ */
127
+ const colorBackground = (text) => {
128
+ const title = titleCase(text);
129
+ return chalk.inverse.hex(getTextColor(title))(` ${title} `);
130
+ };
131
+ const consoleLog = (meta, ...args) => getLogFn(getLogLevel(meta.type), { logLevel: "trace" })(`${meta.name ? chalk.bold.hex(BRAND_COLOR)(kebabCase(meta.name)) : ""}${meta.command ? chalk.hex(BRAND_COLOR)(` (${meta.command})`) : ""}${meta.name ? chalk.grey(" > ") : ""}${(meta.source || meta.plugin) && (!meta.name || kebabCase(meta.source || meta.plugin) !== kebabCase(meta.name)) ? `${chalk.bold.hex(BRAND_COLOR)(kebabCase(meta.source || meta.plugin))}${chalk.grey(" > ")}` : ""}${meta.environment && kebabCase(meta.environment) !== "default" ? `${chalk.bold.hex(BRAND_COLOR)(kebabCase(meta.environment))}${chalk.grey(" > ")}` : ""}${meta.category && meta.category !== LogCategories.GENERAL ? `${colorBackground(kebabCase(meta.category))} ` : ""}${args.join(" ")} `.trim());
132
+ function isValidLogLevel(logLevel, type) {
133
+ if (logLevel === LogLevels.SILENT) return false;
134
+ return LOG_LEVELS.indexOf(logLevel) >= LOG_LEVELS.indexOf(type);
135
+ }
136
+ function isValidLogLevelConfig(type, logLevel, category = LogCategories.GENERAL) {
137
+ return isValidLogLevel(logLevel[category], type);
138
+ }
139
+ /**
140
+ * Create a logging function with a specific name and options.
141
+ *
142
+ * @param name - The name of the logging function.
143
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
144
+ * @returns A logging function.
145
+ */
146
+ const createLogFn = (name, options) => {
147
+ const logLevel = resolveLogLevel(options.logLevel, options.mode);
148
+ return (meta, ...args) => {
149
+ const logMeta = isSetObject(meta) ? {
150
+ logId: uuid(),
151
+ timestamp: Date.now(),
152
+ category: LogCategories.GENERAL,
153
+ ...options,
154
+ ...meta,
155
+ name
156
+ } : {
157
+ logId: uuid(),
158
+ timestamp: Date.now(),
159
+ category: LogCategories.GENERAL,
160
+ ...options,
161
+ type: meta,
162
+ name
163
+ };
164
+ if (isValidLogLevelConfig(logMeta.type, logLevel, logMeta.category ? logMeta.category : LogCategories.GENERAL)) consoleLog(logMeta, ...args);
165
+ };
166
+ };
167
+ const validateLogger = (type, name, options, callback) => {
168
+ const logLevel = resolveLogLevel(options.logLevel, options.mode);
169
+ return (message) => {
170
+ const params = isSetString(message) ? {
171
+ name,
172
+ plugin: options.plugin,
173
+ meta: {
174
+ type,
175
+ name,
176
+ category: LogCategories.GENERAL,
177
+ logId: uuid(),
178
+ timestamp: Date.now(),
179
+ ...options
180
+ },
181
+ message
182
+ } : {
183
+ name,
184
+ plugin: options.plugin,
185
+ ...message,
186
+ meta: {
187
+ type,
188
+ name,
189
+ category: LogCategories.GENERAL,
190
+ logId: uuid(),
191
+ timestamp: Date.now(),
192
+ plugin: message.plugin,
193
+ ...options,
194
+ ...message.meta
195
+ }
196
+ };
197
+ if (isValidLogLevelConfig(type, logLevel, params.meta.category)) callback(params);
198
+ };
199
+ };
200
+ const validateCustomLogger = (type, name, options, callback, customCallback) => {
201
+ const logLevel = resolveLogLevel(options.logLevel, options.mode);
202
+ return (message) => {
203
+ const params = isSetString(message) ? {
204
+ name,
205
+ plugin: options.plugin,
206
+ meta: {
207
+ type,
208
+ name,
209
+ category: LogCategories.GENERAL,
210
+ logId: uuid(),
211
+ timestamp: Date.now(),
212
+ ...options
213
+ },
214
+ message
215
+ } : {
216
+ name,
217
+ plugin: options.plugin,
218
+ ...message,
219
+ meta: {
220
+ type,
221
+ name,
222
+ category: LogCategories.GENERAL,
223
+ logId: uuid(),
224
+ timestamp: Date.now(),
225
+ plugin: message.plugin,
226
+ ...options,
227
+ ...message.meta
228
+ }
229
+ };
230
+ if (isValidLogLevelConfig(type, logLevel, params.meta.category)) {
231
+ callback?.(params);
232
+ customCallback?.(params);
233
+ }
234
+ };
235
+ };
236
+ /**
237
+ * Create a logging function with a specific name and options.
238
+ *
239
+ * @param logger - The original logger to wrap with the custom logger.
240
+ * @param secondaryLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
241
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
242
+ */
243
+ const withLogger = (logger, secondaryLogger) => {
244
+ const options = {
245
+ ...secondaryLogger.options,
246
+ ...logger.options
247
+ };
248
+ const result = {
249
+ options,
250
+ error: validateLogger("error", options.name, options, (message) => {
251
+ logger.error?.(message);
252
+ secondaryLogger.error?.(message);
253
+ }),
254
+ warn: validateLogger("warn", options.name, options, (message) => {
255
+ logger.warn?.(message);
256
+ secondaryLogger.warn?.(message);
257
+ }),
258
+ info: validateLogger("info", options.name, options, (message) => {
259
+ logger.info?.(message);
260
+ secondaryLogger.info?.(message);
261
+ }),
262
+ debug: validateLogger("debug", options.name, options, (message) => {
263
+ logger.debug?.(message);
264
+ secondaryLogger.debug?.(message);
265
+ }),
266
+ trace: validateLogger("trace", options.name, options, (message) => {
267
+ logger.trace?.(message);
268
+ secondaryLogger.trace?.(message);
269
+ })
270
+ };
271
+ result.log = (type, message) => {
272
+ switch (type) {
273
+ case "error":
274
+ result.error(message);
275
+ break;
276
+ case "warn":
277
+ result.warn(message);
278
+ break;
279
+ case "info":
280
+ result.info(message);
281
+ break;
282
+ case "debug":
283
+ result.debug(message);
284
+ break;
285
+ case "trace":
286
+ result.trace(message);
287
+ break;
288
+ case "silent": break;
289
+ default:
290
+ result.info(message);
291
+ break;
292
+ }
293
+ };
294
+ return result;
295
+ };
296
+ /**
297
+ * Create a logging function with a specific name and options.
298
+ *
299
+ * @param logger - The original logger to wrap with the custom logger.
300
+ * @param customLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.
301
+ * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.
302
+ */
303
+ const withCustomLogger = (logger, customLogger) => {
304
+ const result = {
305
+ options: logger.options,
306
+ error: validateCustomLogger("error", logger.options.name, logger.options, logger.error.bind(logger), customLogger.error?.bind(customLogger)),
307
+ warn: validateCustomLogger("warn", logger.options.name, logger.options, logger.warn.bind(logger), customLogger.warn?.bind(customLogger)),
308
+ info: validateCustomLogger("info", logger.options.name, logger.options, logger.info.bind(logger), customLogger.info?.bind(customLogger)),
309
+ debug: validateCustomLogger("debug", logger.options.name, logger.options, logger.debug.bind(logger), customLogger.debug?.bind(customLogger)),
310
+ trace: validateCustomLogger("trace", logger.options.name, logger.options, logger.trace.bind(logger), customLogger.trace?.bind(customLogger))
311
+ };
312
+ result.log = (type, message) => {
313
+ switch (type) {
314
+ case "error":
315
+ result.error(message);
316
+ break;
317
+ case "warn":
318
+ result.warn(message);
319
+ break;
320
+ case "info":
321
+ result.info(message);
322
+ break;
323
+ case "debug":
324
+ result.debug(message);
325
+ break;
326
+ case "trace":
327
+ result.trace(message);
328
+ break;
329
+ case "silent": break;
330
+ default:
331
+ result.info(message);
332
+ break;
333
+ }
334
+ };
335
+ return result;
336
+ };
337
+ const consoleLogger = (type, message) => consoleLog(isSetString(message) ? {
338
+ type,
339
+ category: LogCategories.GENERAL,
340
+ logId: uuid(),
341
+ timestamp: Date.now()
342
+ } : {
343
+ type,
344
+ category: LogCategories.GENERAL,
345
+ logId: uuid(),
346
+ timestamp: Date.now(),
347
+ ...message.meta
348
+ }, isSetString(message) ? message : message.message);
349
+ /**
350
+ * Create a logging function with a specific name and options.
351
+ *
352
+ * @param name - The name of the logging function.
353
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
354
+ * @returns A logging function.
355
+ */
356
+ const createLogger = (name, options, callback = consoleLogger) => {
357
+ const result = {
358
+ options: {
359
+ ...options,
360
+ name
361
+ },
362
+ error: validateLogger("error", name, {
363
+ ...options,
364
+ name
365
+ }, (message) => callback("error", message)),
366
+ warn: validateLogger("warn", name, {
367
+ ...options,
368
+ name
369
+ }, (message) => callback("warn", message)),
370
+ info: validateLogger("info", name, {
371
+ ...options,
372
+ name
373
+ }, (message) => callback("info", message)),
374
+ debug: validateLogger("debug", name, {
375
+ ...options,
376
+ name
377
+ }, (message) => callback("debug", message)),
378
+ trace: validateLogger("trace", name, {
379
+ ...options,
380
+ name
381
+ }, (message) => callback("trace", message))
382
+ };
383
+ result.log = (type, message) => {
384
+ switch (type) {
385
+ case "error":
386
+ result.error(message);
387
+ break;
388
+ case "warn":
389
+ result.warn(message);
390
+ break;
391
+ case "info":
392
+ result.info(message);
393
+ break;
394
+ case "debug":
395
+ result.debug(message);
396
+ break;
397
+ case "trace":
398
+ result.trace(message);
399
+ break;
400
+ case "silent": break;
401
+ default:
402
+ result.info(message);
403
+ break;
404
+ }
405
+ };
406
+ return result;
407
+ };
408
+ /**
409
+ * Extend a logging function with a specific name, adding a colored badge to the log output.
410
+ *
411
+ * @param logFn - The original logging function to extend.
412
+ * @param options - The overlay metadata to use for the badge in the log output.
413
+ * @returns A new logging function that includes the badge in its output.
414
+ */
415
+ const extendLogFn = (logFn, options) => {
416
+ return (meta, ...args) => options.source || options.category ? logFn(isSetObject(meta) ? {
417
+ ...options,
418
+ ...meta
419
+ } : {
420
+ ...options,
421
+ type: meta
422
+ }, `${colorBackground(String(options.source || options.category))} ${args.filter(Boolean).map((arg) => String(arg).trim()).join(" ")} `) : logFn(meta, ...args);
423
+ };
424
+ /**
425
+ * Extend a logger with a specific name and options, adding a colored badge to the log output for each log message generated by the logger.
426
+ *
427
+ * @param logger - The original logger to extend.
428
+ * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the extended logger.
429
+ * @returns A new logger that includes the badge in its output for each log message.
430
+ */
431
+ const extendLogger = (logger, options) => {
432
+ const opts = {
433
+ ...logger.options,
434
+ ...options
435
+ };
436
+ const result = {
437
+ options: opts,
438
+ error: validateLogger("error", opts.name, opts, logger.error.bind(logger)),
439
+ warn: validateLogger("warn", opts.name, opts, logger.warn.bind(logger)),
440
+ info: validateLogger("info", opts.name, opts, logger.info.bind(logger)),
441
+ debug: validateLogger("debug", opts.name, opts, logger.debug.bind(logger)),
442
+ trace: validateLogger("trace", opts.name, opts, logger.trace.bind(logger))
443
+ };
444
+ result.log = (type, message) => {
445
+ switch (type) {
446
+ case "error":
447
+ result.error(message);
448
+ break;
449
+ case "warn":
450
+ result.warn(message);
451
+ break;
452
+ case "info":
453
+ result.info(message);
454
+ break;
455
+ case "debug":
456
+ result.debug(message);
457
+ break;
458
+ case "trace":
459
+ result.trace(message);
460
+ break;
461
+ case "silent": break;
462
+ default:
463
+ result.info(message);
464
+ break;
465
+ }
466
+ };
467
+ return result;
468
+ };
66
469
 
67
470
  //#endregion
68
- export { isVerbose, resolveLogLevel };
471
+ export { colorBackground, colorText, consoleLog, consoleLogger, createLogFn, createLogger, extendLogFn, extendLogger, getTextColor, isValidLogLevel, isValidLogLevelConfig, isVerbose, resolveLogLevel, withCustomLogger, withLogger };
69
472
  //# sourceMappingURL=logging.mjs.map