@mks2508/better-logger 0.0.2-alpha.2 → 0.3.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.
Files changed (326) hide show
  1. package/.claude/settings.local.json +18 -2
  2. package/.github/workflows/ci-quality.yml +357 -0
  3. package/.github/workflows/docs-demo.yml +119 -0
  4. package/.github/workflows/releases-core.yml +512 -0
  5. package/.github/workflows/releases-full.yml +582 -0
  6. package/.github/{workflows → workflows-backup}/ci.yml +12 -110
  7. package/.github/workflows-backup/nightly.yml +196 -0
  8. package/.github/workflows-backup/release-optimized.yml +373 -0
  9. package/.release-notes-0.2.0.md +129 -0
  10. package/.yamllint +28 -0
  11. package/CHANGELOG.json +783 -0
  12. package/CLAUDE.md +92 -1
  13. package/README.md +198 -490
  14. package/bun.lock +323 -0
  15. package/demo.html +9 -2
  16. package/dist/.tsbuildinfo +1 -0
  17. package/dist/Logger.d.ts +272 -0
  18. package/dist/Logger.d.ts.map +1 -0
  19. package/dist/Logger.js +680 -0
  20. package/dist/ScopedLogger.d.ts +126 -0
  21. package/dist/ScopedLogger.d.ts.map +1 -0
  22. package/dist/ScopedLogger.js +234 -0
  23. package/dist/chunks/Logger-BpeuYIxR.js +2 -0
  24. package/dist/chunks/Logger-BpeuYIxR.js.map +1 -0
  25. package/dist/chunks/Logger-Didxtr23.js +3275 -0
  26. package/dist/chunks/Logger-Didxtr23.js.map +1 -0
  27. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
  28. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
  29. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
  30. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
  31. package/dist/chunks/environment-Bxbnw4pd.js +544 -0
  32. package/dist/chunks/environment-Bxbnw4pd.js.map +1 -0
  33. package/dist/chunks/environment-Dm66zOML.js +4 -0
  34. package/dist/chunks/environment-Dm66zOML.js.map +1 -0
  35. package/dist/chunks/formatting-C0riPC5_.js +95 -0
  36. package/dist/chunks/formatting-C0riPC5_.js.map +1 -0
  37. package/dist/chunks/formatting-DNCAV66-.js +2 -0
  38. package/dist/chunks/formatting-DNCAV66-.js.map +1 -0
  39. package/dist/cli/CommandProcessor.d.ts +103 -0
  40. package/dist/cli/CommandProcessor.d.ts.map +1 -0
  41. package/dist/cli/CommandProcessor.js +184 -0
  42. package/dist/cli/commands/ConfigCommand.d.ts +17 -0
  43. package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
  44. package/dist/cli/commands/ConfigCommand.js +88 -0
  45. package/dist/cli/commands/ExportCommand.d.ts +51 -0
  46. package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
  47. package/dist/cli/commands/ExportCommand.js +243 -0
  48. package/dist/cli/commands/HistoryCommand.d.ts +50 -0
  49. package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
  50. package/dist/cli/commands/HistoryCommand.js +96 -0
  51. package/dist/cli/commands/StatusCommand.d.ts +33 -0
  52. package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
  53. package/dist/cli/commands/StatusCommand.js +93 -0
  54. package/dist/cli/commands/ThemeCommand.d.ts +33 -0
  55. package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
  56. package/dist/cli/commands/ThemeCommand.js +79 -0
  57. package/dist/cli/help.d.ts +15 -0
  58. package/dist/cli/help.d.ts.map +1 -0
  59. package/dist/cli/help.js +118 -0
  60. package/dist/cli/index.d.ts +15 -0
  61. package/dist/cli/index.d.ts.map +1 -0
  62. package/dist/cli/index.js +46 -0
  63. package/dist/constants.d.ts +122 -0
  64. package/dist/constants.d.ts.map +1 -0
  65. package/dist/constants.js +159 -0
  66. package/dist/core.cjs +1 -1
  67. package/dist/core.cjs.map +1 -1
  68. package/dist/core.d.ts +134 -0
  69. package/dist/core.d.ts.map +1 -0
  70. package/dist/core.js +315 -242
  71. package/dist/core.js.map +1 -1
  72. package/dist/example.d.ts +18 -0
  73. package/dist/example.d.ts.map +1 -0
  74. package/dist/example.js +154 -0
  75. package/dist/exports-module.d.ts +203 -0
  76. package/dist/exports-module.d.ts.map +1 -0
  77. package/dist/exports-module.js +260 -0
  78. package/dist/exports.cjs +1 -1
  79. package/dist/exports.cjs.map +1 -1
  80. package/dist/exports.js +5 -4
  81. package/dist/exports.js.map +1 -1
  82. package/dist/handlers/AnalyticsLogHandler.d.ts +11 -0
  83. package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  84. package/dist/handlers/AnalyticsLogHandler.js +19 -0
  85. package/dist/handlers/ExportLogHandler.d.ts +103 -0
  86. package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
  87. package/dist/handlers/ExportLogHandler.js +516 -0
  88. package/dist/handlers/FileLogHandler.d.ts +36 -0
  89. package/dist/handlers/FileLogHandler.d.ts.map +1 -0
  90. package/dist/handlers/FileLogHandler.js +156 -0
  91. package/dist/handlers/RemoteLogHandler.d.ts +14 -0
  92. package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
  93. package/dist/handlers/RemoteLogHandler.js +37 -0
  94. package/dist/handlers/index.d.ts +8 -0
  95. package/dist/handlers/index.d.ts.map +1 -0
  96. package/dist/handlers/index.js +7 -0
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.cjs.map +1 -1
  99. package/dist/index.d.ts +86 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +89 -103
  102. package/dist/index.js.map +1 -1
  103. package/dist/main.d.ts +2 -0
  104. package/dist/main.d.ts.map +1 -0
  105. package/dist/main.js +139 -0
  106. package/dist/styling/LogStyleBuilder.d.ts +149 -0
  107. package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
  108. package/dist/styling/LogStyleBuilder.js +289 -0
  109. package/dist/styling/SemanticStyles.d.ts +181 -0
  110. package/dist/styling/SemanticStyles.d.ts.map +1 -0
  111. package/dist/styling/SemanticStyles.js +339 -0
  112. package/dist/styling/SmartPresets.d.ts +25 -0
  113. package/dist/styling/SmartPresets.d.ts.map +1 -0
  114. package/dist/styling/SmartPresets.js +276 -0
  115. package/dist/styling/StyleBuilder.d.ts +140 -0
  116. package/dist/styling/StyleBuilder.d.ts.map +1 -0
  117. package/dist/styling/StyleBuilder.js +280 -0
  118. package/dist/styling/banners.d.ts +45 -0
  119. package/dist/styling/banners.d.ts.map +1 -0
  120. package/dist/styling/banners.js +155 -0
  121. package/dist/styling/index.d.ts +10 -0
  122. package/dist/styling/index.d.ts.map +1 -0
  123. package/dist/styling/index.js +9 -0
  124. package/dist/styling/themes.d.ts +10 -0
  125. package/dist/styling/themes.d.ts.map +1 -0
  126. package/dist/styling/themes.js +231 -0
  127. package/dist/styling-module.d.ts +185 -0
  128. package/dist/styling-module.d.ts.map +1 -0
  129. package/dist/styling-module.js +199 -0
  130. package/dist/styling.cjs +1 -1
  131. package/dist/styling.cjs.map +1 -1
  132. package/dist/styling.js +6 -6
  133. package/dist/styling.js.map +1 -1
  134. package/dist/types/Logger.d.ts +268 -0
  135. package/dist/types/Logger.d.ts.map +1 -0
  136. package/dist/types/ScopedLogger.d.ts +123 -0
  137. package/dist/types/ScopedLogger.d.ts.map +1 -0
  138. package/dist/types/cli/CommandProcessor.d.ts +100 -0
  139. package/dist/types/cli/CommandProcessor.d.ts.map +1 -0
  140. package/dist/types/cli/commands/ConfigCommand.d.ts +14 -0
  141. package/dist/types/cli/commands/ConfigCommand.d.ts.map +1 -0
  142. package/dist/types/cli/commands/ExportCommand.d.ts +48 -0
  143. package/dist/types/cli/commands/ExportCommand.d.ts.map +1 -0
  144. package/dist/types/cli/commands/HistoryCommand.d.ts +47 -0
  145. package/dist/types/cli/commands/HistoryCommand.d.ts.map +1 -0
  146. package/dist/types/cli/commands/StatusCommand.d.ts +30 -0
  147. package/dist/types/cli/commands/StatusCommand.d.ts.map +1 -0
  148. package/dist/types/cli/commands/ThemeCommand.d.ts +30 -0
  149. package/dist/types/cli/commands/ThemeCommand.d.ts.map +1 -0
  150. package/dist/types/cli/help.d.ts +12 -0
  151. package/dist/types/cli/help.d.ts.map +1 -0
  152. package/dist/types/cli/index.d.ts +15 -0
  153. package/dist/types/cli/index.d.ts.map +1 -0
  154. package/dist/types/constants.d.ts +119 -0
  155. package/dist/types/constants.d.ts.map +1 -0
  156. package/dist/types/core.d.ts +125 -211
  157. package/dist/types/core.d.ts.map +1 -0
  158. package/dist/types/core.js +13 -0
  159. package/dist/types/example.d.ts +18 -0
  160. package/dist/types/example.d.ts.map +1 -0
  161. package/dist/types/exports-module.d.ts +196 -0
  162. package/dist/types/exports-module.d.ts.map +1 -0
  163. package/dist/types/handlers/AnalyticsLogHandler.d.ts +8 -0
  164. package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  165. package/dist/types/handlers/ExportLogHandler.d.ts +100 -0
  166. package/dist/types/handlers/ExportLogHandler.d.ts.map +1 -0
  167. package/dist/types/handlers/FileLogHandler.d.ts +33 -0
  168. package/dist/types/handlers/FileLogHandler.d.ts.map +1 -0
  169. package/dist/types/handlers/RemoteLogHandler.d.ts +11 -0
  170. package/dist/types/handlers/RemoteLogHandler.d.ts.map +1 -0
  171. package/dist/types/handlers/index.d.ts +8 -0
  172. package/dist/types/handlers/index.d.ts.map +1 -0
  173. package/dist/types/handlers.d.ts +88 -0
  174. package/dist/types/handlers.d.ts.map +1 -0
  175. package/dist/types/handlers.js +4 -0
  176. package/dist/types/index.d.ts +7 -675
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/index.js +4 -0
  179. package/dist/types/main.d.ts +2 -0
  180. package/dist/types/main.d.ts.map +1 -0
  181. package/dist/types/styling/LogStyleBuilder.d.ts +146 -0
  182. package/dist/types/styling/LogStyleBuilder.d.ts.map +1 -0
  183. package/dist/types/styling/SemanticStyles.d.ts +178 -0
  184. package/dist/types/styling/SemanticStyles.d.ts.map +1 -0
  185. package/dist/types/styling/SmartPresets.d.ts +22 -0
  186. package/dist/types/styling/SmartPresets.d.ts.map +1 -0
  187. package/dist/types/styling/StyleBuilder.d.ts +140 -0
  188. package/dist/types/styling/StyleBuilder.d.ts.map +1 -0
  189. package/dist/types/styling/banners.d.ts +42 -0
  190. package/dist/types/styling/banners.d.ts.map +1 -0
  191. package/dist/types/styling/index.d.ts +10 -0
  192. package/dist/types/styling/index.d.ts.map +1 -0
  193. package/dist/types/styling/themes.d.ts +7 -0
  194. package/dist/types/styling/themes.d.ts.map +1 -0
  195. package/dist/types/styling-module.d.ts +178 -0
  196. package/dist/types/styling-module.d.ts.map +1 -0
  197. package/dist/types/types/core.d.ts +125 -0
  198. package/dist/types/types/core.d.ts.map +1 -0
  199. package/dist/types/types/handlers.d.ts +85 -0
  200. package/dist/types/types/handlers.d.ts.map +1 -0
  201. package/dist/types/types/index.d.ts +7 -0
  202. package/dist/types/types/index.d.ts.map +1 -0
  203. package/dist/types/utils/environment.d.ts +47 -0
  204. package/dist/types/utils/environment.d.ts.map +1 -0
  205. package/dist/types/utils/formatting.d.ts +37 -0
  206. package/dist/types/utils/formatting.d.ts.map +1 -0
  207. package/dist/types/utils/index.d.ts +7 -0
  208. package/dist/types/utils/index.d.ts.map +1 -0
  209. package/dist/types/utils/opentui-detection.d.ts +34 -0
  210. package/dist/types/utils/opentui-detection.d.ts.map +1 -0
  211. package/dist/types/utils/output.d.ts +41 -0
  212. package/dist/types/utils/output.d.ts.map +1 -0
  213. package/dist/types/utils/stackTrace.d.ts +6 -0
  214. package/dist/types/utils/stackTrace.d.ts.map +1 -0
  215. package/dist/types/utils/timestamps.d.ts +20 -0
  216. package/dist/types/utils/timestamps.d.ts.map +1 -0
  217. package/dist/utils/environment.d.ts +47 -0
  218. package/dist/utils/environment.d.ts.map +1 -0
  219. package/dist/utils/environment.js +85 -0
  220. package/dist/utils/formatting.d.ts +40 -0
  221. package/dist/utils/formatting.d.ts.map +1 -0
  222. package/dist/utils/formatting.js +117 -0
  223. package/dist/utils/index.d.ts +7 -0
  224. package/dist/utils/index.d.ts.map +1 -0
  225. package/dist/utils/index.js +6 -0
  226. package/dist/utils/opentui-detection.d.ts +34 -0
  227. package/dist/utils/opentui-detection.d.ts.map +1 -0
  228. package/dist/utils/opentui-detection.js +116 -0
  229. package/dist/utils/output.d.ts +44 -0
  230. package/dist/utils/output.d.ts.map +1 -0
  231. package/dist/utils/output.js +150 -0
  232. package/dist/utils/stackTrace.d.ts +9 -0
  233. package/dist/utils/stackTrace.d.ts.map +1 -0
  234. package/dist/utils/stackTrace.js +81 -0
  235. package/dist/utils/timestamps.d.ts +20 -0
  236. package/dist/utils/timestamps.d.ts.map +1 -0
  237. package/dist/utils/timestamps.js +71 -0
  238. package/docs/API.md +691 -0
  239. package/docs/CORE.md +10 -10
  240. package/docs/DEVELOPMENT.md +731 -0
  241. package/docs/PACKAGES.md +244 -0
  242. package/docs/_config.yml +36 -0
  243. package/docs/index.md +179 -0
  244. package/examples/README.md +208 -0
  245. package/examples/basic-logging.js +75 -0
  246. package/examples/data-export.js +234 -0
  247. package/examples/package.json +16 -0
  248. package/examples/performance-timing.js +170 -0
  249. package/examples/simplified-api.js +124 -0
  250. package/examples/styling-themes.js +207 -0
  251. package/package.json +37 -21
  252. package/packages/core/package.json +57 -0
  253. package/packages/exports/package.json +41 -0
  254. package/packages/nodejs-opentui/README.md +232 -0
  255. package/packages/nodejs-opentui/package.json +72 -0
  256. package/packages/nodejs-opentui/src/LogRenderer.ts +171 -0
  257. package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +178 -0
  258. package/packages/nodejs-opentui/src/components/LogBadge.tsx +131 -0
  259. package/packages/nodejs-opentui/src/index.ts +133 -0
  260. package/packages/nodejs-opentui/src/types.ts +158 -0
  261. package/packages/nodejs-opentui/tsconfig.json +20 -0
  262. package/packages/styling/package.json +41 -0
  263. package/project-utils/README.md +172 -0
  264. package/project-utils/auto-release-gemini.ts +1193 -0
  265. package/project-utils/auto-release-ui.ts +1329 -0
  266. package/project-utils/commit-generator.ts +1385 -0
  267. package/project-utils/commit-ui.ts +264 -0
  268. package/project-utils/git-utils.ts +199 -0
  269. package/project-utils/github-release-manager.ts +466 -0
  270. package/project-utils/project-config.ts +260 -0
  271. package/project-utils/prompt-templates.js +345 -0
  272. package/project-utils/prompt-templates.ts +422 -0
  273. package/project-utils/version-manager.ts +1078 -0
  274. package/src/Logger.ts +251 -16
  275. package/src/ScopedLogger.ts +262 -0
  276. package/src/cli/CommandProcessor.ts +173 -2
  277. package/src/cli/commands/HistoryCommand.ts +117 -0
  278. package/src/cli/index.ts +12 -0
  279. package/src/constants.ts +84 -2
  280. package/src/core.ts +119 -46
  281. package/src/example.ts +4 -4
  282. package/src/exports-module.ts +1 -1
  283. package/src/handlers/ExportLogHandler.ts +141 -0
  284. package/src/handlers/FileLogHandler.ts +144 -5
  285. package/src/index.ts +1 -1
  286. package/src/main.ts +3 -3
  287. package/src/styling/LogStyleBuilder.ts +355 -0
  288. package/src/styling/SemanticStyles.ts +380 -0
  289. package/src/styling/SmartPresets.ts +288 -0
  290. package/src/styling/StyleBuilder.ts +14 -0
  291. package/src/styling/index.ts +16 -1
  292. package/src/styling-module.ts +1 -1
  293. package/src/types/core.ts +60 -0
  294. package/src/types/index.ts +6 -0
  295. package/src/utils/environment.ts +94 -0
  296. package/src/utils/formatting.ts +142 -0
  297. package/src/utils/index.ts +3 -0
  298. package/src/utils/opentui-detection.ts +138 -0
  299. package/src/utils/output.ts +66 -8
  300. package/test-core-browser.html +237 -0
  301. package/test-core-node.js +63 -0
  302. package/tests/test-conflict-resolution.ts +391 -0
  303. package/tests/validate-workflows.sh +131 -0
  304. package/tests/yaml-autofix.sh +146 -0
  305. package/vite.config.ts +189 -50
  306. package/.npmrc.bak +0 -1
  307. package/dist/chunks/Logger-BQhMKy_T.js +0 -2
  308. package/dist/chunks/Logger-BQhMKy_T.js.map +0 -1
  309. package/dist/chunks/Logger-BrFKFZcD.js +0 -978
  310. package/dist/chunks/Logger-BrFKFZcD.js.map +0 -1
  311. package/dist/chunks/core-2opW4Pi3.js +0 -194
  312. package/dist/chunks/core-2opW4Pi3.js.map +0 -1
  313. package/dist/chunks/core-DyugwSYZ.js +0 -4
  314. package/dist/chunks/core-DyugwSYZ.js.map +0 -1
  315. package/dist/chunks/exports-BNP3R7dp.js +0 -421
  316. package/dist/chunks/exports-BNP3R7dp.js.map +0 -1
  317. package/dist/chunks/exports-U1xLBXrY.js +0 -2
  318. package/dist/chunks/exports-U1xLBXrY.js.map +0 -1
  319. package/dist/chunks/styling-DhUDzwlE.js +0 -654
  320. package/dist/chunks/styling-DhUDzwlE.js.map +0 -1
  321. package/dist/chunks/styling-tmRDI28D.js +0 -2
  322. package/dist/chunks/styling-tmRDI28D.js.map +0 -1
  323. package/dist/types/exports.d.ts +0 -600
  324. package/dist/types/styling.d.ts +0 -751
  325. package/src/Logger.ts.backup +0 -1684
  326. /package/.github/{workflows → workflows-backup}/release.yml +0 -0
package/dist/Logger.js ADDED
@@ -0,0 +1,680 @@
1
+ /**
2
+ * @fileoverview Refactored Advanced Logger with modular architecture
3
+ * @version 2.0.0
4
+ */
5
+ // Utility imports
6
+ import { parseStackTrace, formatTimestamp, createStyledOutput, setupThemeChangeListener } from './utils/index.js';
7
+ // Styling imports
8
+ import { THEME_PRESETS, THEME_BANNERS, displayInitBanner, StylePresets, StyleBuilder } from './styling/index.js';
9
+ // Smart presets and scoped loggers
10
+ import { getSmartPreset, getAvailablePresets, hasPreset } from './styling/SmartPresets.js';
11
+ import { ScopedLogger, APILogger, ComponentLogger } from './ScopedLogger.js';
12
+ import { createLogStyleBuilder } from './styling/LogStyleBuilder.js';
13
+ // Handler imports
14
+ import { ExportLogHandler } from './handlers/index.js';
15
+ // CLI imports
16
+ import { createDefaultCLI } from './cli/index.js';
17
+ // Constants
18
+ import { DEFAULT_CONFIG } from './constants.js';
19
+ /**
20
+ * Current active theme styles
21
+ */
22
+ let LEVEL_STYLES = THEME_PRESETS.default;
23
+ /**
24
+ * Main Logger class implementing state-of-the-art logging capabilities
25
+ */
26
+ export class Logger {
27
+ config;
28
+ scopedPrefix;
29
+ handlers = [];
30
+ timers = new Map();
31
+ groupDepth = 0;
32
+ exportHandler;
33
+ cliProcessor;
34
+ themeChangeListener;
35
+ displaySettings = {
36
+ showTimestamp: true,
37
+ showLocation: true,
38
+ showBadges: true
39
+ };
40
+ /**
41
+ * Creates a new Logger instance
42
+ */
43
+ constructor(config = {}) {
44
+ this.config = {
45
+ ...DEFAULT_CONFIG,
46
+ ...config,
47
+ };
48
+ // Initialize export handler if buffer size is specified
49
+ if (this.config.bufferSize) {
50
+ this.exportHandler = new ExportLogHandler(this.config.bufferSize);
51
+ this.handlers.push(this.exportHandler);
52
+ }
53
+ // Initialize CLI processor
54
+ this.cliProcessor = createDefaultCLI();
55
+ // Set up theme change listener if auto-detection is enabled
56
+ if (this.config.autoDetectTheme) {
57
+ this.setupAutoThemeDetection();
58
+ }
59
+ }
60
+ // ===== PRIVATE HELPER METHODS =====
61
+ /**
62
+ * Sets up automatic theme detection with change listener
63
+ */
64
+ setupAutoThemeDetection() {
65
+ // Clean up existing listener if any
66
+ if (this.themeChangeListener) {
67
+ this.themeChangeListener();
68
+ this.themeChangeListener = null;
69
+ }
70
+ // Set up new listener
71
+ this.themeChangeListener = setupThemeChangeListener((theme) => {
72
+ // Theme changed - logs will automatically use new colors on next call
73
+ // No need to update anything as colors are resolved dynamically
74
+ this.debug(`DevTools theme changed to: ${theme}`);
75
+ });
76
+ }
77
+ // ===== CONFIGURATION METHODS =====
78
+ /**
79
+ * Get current configuration
80
+ */
81
+ getConfig() {
82
+ return { ...this.config };
83
+ }
84
+ /**
85
+ * Update configuration
86
+ */
87
+ updateConfig(updates) {
88
+ const previousAutoDetect = this.config.autoDetectTheme;
89
+ this.config = { ...this.config, ...updates };
90
+ // Handle auto-detection changes
91
+ if (updates.autoDetectTheme !== undefined && updates.autoDetectTheme !== previousAutoDetect) {
92
+ if (updates.autoDetectTheme) {
93
+ this.setupAutoThemeDetection();
94
+ }
95
+ else if (this.themeChangeListener) {
96
+ this.themeChangeListener();
97
+ this.themeChangeListener = null;
98
+ }
99
+ }
100
+ }
101
+ /**
102
+ * Sets the global prefix for all log messages
103
+ */
104
+ setGlobalPrefix(prefix) {
105
+ this.config.globalPrefix = prefix;
106
+ }
107
+ /**
108
+ * Sets the verbosity level for filtering log output
109
+ */
110
+ setVerbosity(level) {
111
+ this.config.verbosity = level;
112
+ }
113
+ /**
114
+ * Sets the logger theme
115
+ */
116
+ setTheme(theme) {
117
+ // First check if it's a smart preset
118
+ if (hasPreset(theme)) {
119
+ this.preset(theme);
120
+ return;
121
+ }
122
+ // Fallback to old theme system
123
+ if (theme in THEME_PRESETS) {
124
+ LEVEL_STYLES = THEME_PRESETS[theme];
125
+ this.config.theme = theme;
126
+ // Show theme-specific banner
127
+ if (theme in THEME_BANNERS) {
128
+ const themeBanner = THEME_BANNERS[theme];
129
+ console.log(`%c${themeBanner.simple}`, themeBanner.style);
130
+ }
131
+ this.success(`Theme changed to: ${theme}`);
132
+ }
133
+ else {
134
+ this.error(`Invalid theme: ${theme}. Available:`, [...getAvailablePresets(), ...Object.keys(THEME_PRESETS)]);
135
+ }
136
+ }
137
+ /**
138
+ * Set banner type for initialization display
139
+ */
140
+ setBannerType(bannerType) {
141
+ this.config.bannerType = bannerType;
142
+ this.success(`Banner type changed to: ${bannerType}`);
143
+ }
144
+ /**
145
+ * Reset logger to default configuration
146
+ */
147
+ resetConfig() {
148
+ // Clean up theme listener
149
+ if (this.themeChangeListener) {
150
+ this.themeChangeListener();
151
+ this.themeChangeListener = null;
152
+ }
153
+ this.config = { ...DEFAULT_CONFIG };
154
+ LEVEL_STYLES = THEME_PRESETS.default;
155
+ // Re-setup auto theme detection if enabled in default config
156
+ if (this.config.autoDetectTheme) {
157
+ this.setupAutoThemeDetection();
158
+ }
159
+ this.success('Logger configuration reset to defaults');
160
+ }
161
+ /**
162
+ * Cleanup method to remove event listeners and free resources
163
+ */
164
+ cleanup() {
165
+ if (this.themeChangeListener) {
166
+ this.themeChangeListener();
167
+ this.themeChangeListener = null;
168
+ }
169
+ }
170
+ // ===== SIMPLIFIED API =====
171
+ /**
172
+ * Apply a smart preset - works perfectly out-of-the-box
173
+ */
174
+ preset(name) {
175
+ if (!hasPreset(name)) {
176
+ this.error(`Unknown preset: ${name}. Available presets:`, getAvailablePresets());
177
+ return;
178
+ }
179
+ const presetConfig = getSmartPreset(name);
180
+ if (presetConfig) {
181
+ // Apply the smart preset configuration
182
+ this.displaySettings.showTimestamp = presetConfig.timestamp?.show ?? true;
183
+ this.displaySettings.showLocation = presetConfig.location?.show ?? true;
184
+ // Store the preset config for use in createStyledOutput
185
+ this._activePreset = presetConfig;
186
+ this._activePresetName = name;
187
+ this.success(`Applied preset: ${name}`);
188
+ }
189
+ }
190
+ /**
191
+ * List available presets
192
+ */
193
+ presets() {
194
+ return getAvailablePresets();
195
+ }
196
+ // ===== TOGGLE METHODS =====
197
+ /**
198
+ * Hide timestamp in logs
199
+ */
200
+ hideTimestamp() {
201
+ this.displaySettings.showTimestamp = false;
202
+ this.success('Timestamp hidden');
203
+ }
204
+ /**
205
+ * Show timestamp in logs
206
+ */
207
+ showTimestamp() {
208
+ this.displaySettings.showTimestamp = true;
209
+ this.success('Timestamp shown');
210
+ }
211
+ /**
212
+ * Hide location info in logs
213
+ */
214
+ hideLocation() {
215
+ this.displaySettings.showLocation = false;
216
+ this.success('Location info hidden');
217
+ }
218
+ /**
219
+ * Show location info in logs
220
+ */
221
+ showLocation() {
222
+ this.displaySettings.showLocation = true;
223
+ this.success('Location info shown');
224
+ }
225
+ /**
226
+ * Hide badges in logs
227
+ */
228
+ hideBadges() {
229
+ this.displaySettings.showBadges = false;
230
+ this.success('Badges hidden');
231
+ }
232
+ /**
233
+ * Show badges in logs
234
+ */
235
+ showBadges() {
236
+ this.displaySettings.showBadges = true;
237
+ this.success('Badges shown');
238
+ }
239
+ // ===== SCOPED LOGGERS =====
240
+ /**
241
+ * Create a component logger with automatic styling
242
+ */
243
+ component(name) {
244
+ return new ComponentLogger(this, name);
245
+ }
246
+ /**
247
+ * Create an API logger with automatic badges
248
+ */
249
+ api(name) {
250
+ return new APILogger(this, name);
251
+ }
252
+ /**
253
+ * Create a general scoped logger with badges support
254
+ */
255
+ scope(name) {
256
+ return new ScopedLogger(this, name);
257
+ }
258
+ // ===== SIMPLE CUSTOMIZATION =====
259
+ /**
260
+ * Simple customization with minimal configuration
261
+ */
262
+ customize(overrides) {
263
+ // Apply simple overrides
264
+ if (overrides.timestamp?.show !== undefined) {
265
+ this.displaySettings.showTimestamp = overrides.timestamp.show;
266
+ }
267
+ if (overrides.location?.show !== undefined) {
268
+ this.displaySettings.showLocation = overrides.location.show;
269
+ }
270
+ if (overrides.prefix?.show !== undefined) {
271
+ // Will be handled when we integrate with preset system
272
+ }
273
+ // Store customization for use in createStyledOutput
274
+ this._customization = overrides;
275
+ this.success('Customization applied');
276
+ }
277
+ /**
278
+ * Access advanced styling API (for power users)
279
+ */
280
+ styles() {
281
+ return createLogStyleBuilder(this);
282
+ }
283
+ // ===== HANDLER MANAGEMENT =====
284
+ /**
285
+ * Adds a custom log handler for extensibility
286
+ */
287
+ addHandler(handler) {
288
+ this.handlers.push(handler);
289
+ }
290
+ /**
291
+ * Get all registered handlers
292
+ */
293
+ getHandlers() {
294
+ return [...this.handlers];
295
+ }
296
+ /**
297
+ * Get export handler if available
298
+ */
299
+ getExportHandler() {
300
+ return this.exportHandler;
301
+ }
302
+ // ===== CORE LOGGING METHODS =====
303
+ /**
304
+ * Checks if a log level should be output based on current verbosity
305
+ */
306
+ shouldLog(level) {
307
+ if (this.config.verbosity === 'silent')
308
+ return false;
309
+ const levels = { debug: 0, info: 1, warn: 2, error: 3, critical: 4 };
310
+ return levels[level] >= levels[this.config.verbosity];
311
+ }
312
+ /**
313
+ * Gets the effective prefix (global + scoped)
314
+ */
315
+ getEffectivePrefix() {
316
+ const parts = [this.config.globalPrefix, this.scopedPrefix].filter(Boolean);
317
+ return parts.length > 0 ? parts.join(':') : undefined;
318
+ }
319
+ /**
320
+ * Core logging method that handles styling and formatting
321
+ */
322
+ log(level, ...args) {
323
+ if (!this.shouldLog(level))
324
+ return;
325
+ const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
326
+ const prefix = this.getEffectivePrefix();
327
+ const message = args.length > 0 ? String(args[0]) : '';
328
+ const additionalArgs = args.slice(1);
329
+ // Create styled output with theme detection and display settings
330
+ const [format, ...styles] = createStyledOutput(level, LEVEL_STYLES, prefix, message, this.displaySettings.showLocation ? stackInfo : null, this.config.autoDetectTheme);
331
+ // Add group indentation
332
+ const groupIndent = ' '.repeat(this.groupDepth);
333
+ const finalFormat = groupIndent + format;
334
+ // Output to console
335
+ if (additionalArgs.length > 0) {
336
+ console.log(finalFormat, ...styles, ...additionalArgs);
337
+ }
338
+ else {
339
+ console.log(finalFormat, ...styles);
340
+ }
341
+ // Update export handler group info
342
+ if (this.exportHandler) {
343
+ this.exportHandler.setGroupInfo(this.groupDepth);
344
+ }
345
+ // Call custom handlers
346
+ const metadata = {
347
+ timestamp: formatTimestamp(),
348
+ level,
349
+ prefix,
350
+ stackInfo: stackInfo ? stackInfo : undefined,
351
+ };
352
+ this.handlers.forEach(handler => {
353
+ try {
354
+ handler.handle(level, message, args, metadata);
355
+ }
356
+ catch (error) {
357
+ console.error('Log handler failed:', error);
358
+ }
359
+ });
360
+ }
361
+ /**
362
+ * Logs debug information (lowest priority)
363
+ */
364
+ debug(...args) {
365
+ this.log('debug', ...args);
366
+ }
367
+ /**
368
+ * Logs informational messages
369
+ */
370
+ info(...args) {
371
+ this.log('info', ...args);
372
+ }
373
+ /**
374
+ * Logs warning messages
375
+ */
376
+ warn(...args) {
377
+ this.log('warn', ...args);
378
+ }
379
+ /**
380
+ * Logs error messages
381
+ */
382
+ error(...args) {
383
+ this.log('error', ...args);
384
+ }
385
+ /**
386
+ * Logs success messages (special info level)
387
+ */
388
+ success(...args) {
389
+ if (!this.shouldLog('info'))
390
+ return;
391
+ const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
392
+ const prefix = this.getEffectivePrefix();
393
+ const message = args.length > 0 ? String(args[0]) : '';
394
+ const additionalArgs = args.slice(1);
395
+ // Handle success as special case - use info level with success styling
396
+ const [format, ...styles] = createStyledOutput('info', LEVEL_STYLES, prefix, message, this.displaySettings.showLocation ? stackInfo : null, this.config.autoDetectTheme);
397
+ // Override with success styling
398
+ const successStyle = LEVEL_STYLES.success;
399
+ let emoji = '✅';
400
+ let label = 'SUCCESS';
401
+ if (successStyle) {
402
+ if (successStyle.emoji) {
403
+ emoji = successStyle.emoji;
404
+ }
405
+ if (successStyle.label) {
406
+ label = successStyle.label;
407
+ }
408
+ }
409
+ const successFormat = format.replace(/ℹ️ INFO/, `${emoji} ${label}`);
410
+ const groupIndent = ' '.repeat(this.groupDepth);
411
+ const finalFormat = groupIndent + successFormat;
412
+ if (additionalArgs.length > 0) {
413
+ console.log(finalFormat, ...styles, ...additionalArgs);
414
+ }
415
+ else {
416
+ console.log(finalFormat, ...styles);
417
+ }
418
+ // Call handlers
419
+ const metadata = {
420
+ timestamp: formatTimestamp(),
421
+ level: 'info',
422
+ prefix,
423
+ stackInfo: stackInfo ? stackInfo : undefined,
424
+ };
425
+ this.handlers.forEach(handler => {
426
+ try {
427
+ handler.handle('info', message, args, metadata);
428
+ }
429
+ catch (error) {
430
+ console.error('Log handler failed:', error);
431
+ }
432
+ });
433
+ }
434
+ /**
435
+ * Logs trace information (detailed debugging)
436
+ */
437
+ trace(...args) {
438
+ this.log('debug', ...args);
439
+ if (this.shouldLog('debug')) {
440
+ console.trace(...args);
441
+ }
442
+ }
443
+ /**
444
+ * Logs critical errors (highest priority)
445
+ */
446
+ critical(...args) {
447
+ this.log('critical', ...args);
448
+ }
449
+ // ===== ADVANCED LOGGING FEATURES =====
450
+ /**
451
+ * Displays data in a table format
452
+ */
453
+ table(data, columns) {
454
+ if (!this.shouldLog('info'))
455
+ return;
456
+ const prefix = this.getEffectivePrefix();
457
+ const tableStyle = StylePresets.accent().build();
458
+ const format = `%c📊 TABLE${prefix ? ` [${prefix}]` : ''}`;
459
+ console.log(format, tableStyle);
460
+ if (columns) {
461
+ console.table(data, columns);
462
+ }
463
+ else {
464
+ console.table(data);
465
+ }
466
+ }
467
+ /**
468
+ * Starts a collapsible group in the console
469
+ */
470
+ group(label, collapsed = false) {
471
+ const groupStyle = new StyleBuilder()
472
+ .bg('linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%)')
473
+ .color('#1565c0')
474
+ .border('1px solid #90caf9')
475
+ .padding('4px 12px')
476
+ .rounded('6px')
477
+ .bold()
478
+ .build();
479
+ const format = `%c📁 ${label}`;
480
+ if (collapsed) {
481
+ console.groupCollapsed(format, groupStyle);
482
+ }
483
+ else {
484
+ console.group(format, groupStyle);
485
+ }
486
+ this.groupDepth++;
487
+ }
488
+ /**
489
+ * Ends the current console group
490
+ */
491
+ groupEnd() {
492
+ if (this.groupDepth > 0) {
493
+ console.groupEnd();
494
+ this.groupDepth--;
495
+ }
496
+ }
497
+ // ===== PERFORMANCE TIMING =====
498
+ /**
499
+ * Starts a timer with the given label
500
+ */
501
+ time(label) {
502
+ const timer = {
503
+ label,
504
+ startTime: performance.now(),
505
+ };
506
+ this.timers.set(label, timer);
507
+ const timerStyle = StylePresets.warning().build();
508
+ console.log(`%c⏱️ Timer started: ${label}`, timerStyle);
509
+ }
510
+ /**
511
+ * Ends a timer and logs the elapsed time
512
+ */
513
+ timeEnd(label) {
514
+ const timer = this.timers.get(label);
515
+ if (!timer) {
516
+ this.warn(`Timer '${label}' does not exist`);
517
+ return;
518
+ }
519
+ const elapsed = performance.now() - timer.startTime;
520
+ this.timers.delete(label);
521
+ const timerStyle = StylePresets.success().build();
522
+ console.log(`%c⏱️ Timer ended: ${label} - ${elapsed.toFixed(2)}ms`, timerStyle);
523
+ }
524
+ // ===== ADVANCED VISUAL FEATURES =====
525
+ /**
526
+ * Display banner with specified or configured type
527
+ */
528
+ showBanner(bannerType) {
529
+ const effectiveBannerType = bannerType ? bannerType : this.config.bannerType;
530
+ displayInitBanner(effectiveBannerType);
531
+ }
532
+ /**
533
+ * Log with SVG background image
534
+ */
535
+ logWithSVG(message, svgContent, options = {}) {
536
+ const { width = 300, height = 60, padding = '30px 150px' } = options;
537
+ let svgDataUri = '';
538
+ if (svgContent) {
539
+ const encodedSVG = encodeURIComponent(svgContent);
540
+ svgDataUri = `data:image/svg+xml,${encodedSVG}`;
541
+ }
542
+ else {
543
+ const defaultSVG = `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${width} ${height}'><defs><linearGradient id='grad' x1='0%' y1='0%' x2='100%' y2='0%'><stop offset='0%' style='stop-color:%23667eea'/><stop offset='100%' style='stop-color:%23764ba2'/></linearGradient></defs><rect width='100%' height='100%' fill='url(%23grad)' rx='4'/><text x='${width / 2}' y='${height / 2 + 5}' text-anchor='middle' fill='white' font-family='monospace' font-size='14' font-weight='bold'>${message}</text></svg>`;
544
+ svgDataUri = `data:image/svg+xml,${encodeURIComponent(defaultSVG)}`;
545
+ }
546
+ const svgStyle = new StyleBuilder()
547
+ .bg(`url("${svgDataUri}") no-repeat center center`)
548
+ .padding(padding)
549
+ .color('transparent')
550
+ .rounded('4px')
551
+ .build();
552
+ console.log(`%c${message}`, svgStyle);
553
+ }
554
+ /**
555
+ * Log with animated background gradient
556
+ */
557
+ logAnimated(message, duration = 3) {
558
+ // Inject CSS animation if not already present
559
+ if (!document.getElementById('logger-animations')) {
560
+ const style = document.createElement('style');
561
+ style.id = 'logger-animations';
562
+ style.textContent = `
563
+ @keyframes loggerGradient {
564
+ 0% { background-position: 0% 50%; }
565
+ 50% { background-position: 100% 50%; }
566
+ 100% { background-position: 0% 50%; }
567
+ }
568
+ `;
569
+ document.head.appendChild(style);
570
+ }
571
+ const animatedStyle = new StyleBuilder()
572
+ .bg('linear-gradient(-45deg, #667eea, #764ba2, #667eea, #764ba2)')
573
+ .css('background-size', '400% 400%')
574
+ .color('#ffffff')
575
+ .padding('12px 20px')
576
+ .rounded('8px')
577
+ .bold()
578
+ .font('Monaco, Consolas, monospace')
579
+ .animation(`loggerGradient ${duration}s ease infinite`)
580
+ .display('inline-block')
581
+ .build();
582
+ console.log(`%c${message}`, animatedStyle);
583
+ }
584
+ /**
585
+ * Groups logs by a specific property using modern Object.groupBy (when available)
586
+ */
587
+ logGrouped(items, groupBy) {
588
+ try {
589
+ // Use Object.groupBy if available (ES2024), otherwise fallback to reduce
590
+ let grouped;
591
+ if (Object.groupBy) {
592
+ grouped = Object.groupBy(items, groupBy);
593
+ }
594
+ else {
595
+ grouped = items.reduce((acc, item) => {
596
+ const key = groupBy(item);
597
+ if (!acc[key]) {
598
+ acc[key] = [];
599
+ }
600
+ acc[key].push(item);
601
+ return acc;
602
+ }, {});
603
+ }
604
+ Object.entries(grouped).forEach(([group, groupItems]) => {
605
+ this.group(`Group: ${group}`);
606
+ this.table(groupItems);
607
+ this.groupEnd();
608
+ });
609
+ }
610
+ catch {
611
+ this.info('Grouped data:', items);
612
+ }
613
+ }
614
+ // ===== CLI SYSTEM =====
615
+ /**
616
+ * CLI command processor for logger configuration and export
617
+ */
618
+ async cli(command) {
619
+ if (!this.cliProcessor) {
620
+ this.error('CLI processor not initialized');
621
+ return;
622
+ }
623
+ await this.cliProcessor.processCommand(command, this);
624
+ }
625
+ }
626
+ // Create and export the singleton instance
627
+ const defaultLogger = new Logger({
628
+ verbosity: 'info',
629
+ enableColors: true,
630
+ enableTimestamps: true,
631
+ enableStackTrace: true,
632
+ bufferSize: 1000, // Enable export functionality by default
633
+ });
634
+ // Display initialization banner
635
+ displayInitBanner();
636
+ // Export the singleton instance as default
637
+ export default defaultLogger;
638
+ /**
639
+ * Export individual methods for convenience (with proper binding)
640
+ */
641
+ export const debug = (...args) => defaultLogger.debug(...args);
642
+ export const info = (...args) => defaultLogger.info(...args);
643
+ export const warn = (...args) => defaultLogger.warn(...args);
644
+ export const error = (...args) => defaultLogger.error(...args);
645
+ export const success = (...args) => defaultLogger.success(...args);
646
+ export const trace = (...args) => defaultLogger.trace(...args);
647
+ export const critical = (...args) => defaultLogger.critical(...args);
648
+ export const table = (data, columns) => defaultLogger.table(data, columns);
649
+ export const group = (label, collapsed) => defaultLogger.group(label, collapsed);
650
+ export const groupEnd = () => defaultLogger.groupEnd();
651
+ export const time = (label) => defaultLogger.time(label);
652
+ export const timeEnd = (label) => defaultLogger.timeEnd(label);
653
+ export const setGlobalPrefix = (prefix) => defaultLogger.setGlobalPrefix(prefix);
654
+ export const setVerbosity = (level) => defaultLogger.setVerbosity(level);
655
+ export const addHandler = (handler) => defaultLogger.addHandler(handler);
656
+ export const setTheme = (theme) => defaultLogger.setTheme(theme);
657
+ export const setBannerType = (bannerType) => defaultLogger.setBannerType(bannerType);
658
+ export const showBanner = (bannerType) => defaultLogger.showBanner(bannerType);
659
+ export const logWithSVG = (message, svgContent, options) => defaultLogger.logWithSVG(message, svgContent, options);
660
+ export const logAnimated = (message, duration) => defaultLogger.logAnimated(message, duration);
661
+ export const cli = (command) => defaultLogger.cli(command);
662
+ export const cleanup = () => defaultLogger.cleanup();
663
+ // Simplified API exports
664
+ export const preset = (name) => defaultLogger.preset(name);
665
+ export const presets = () => defaultLogger.presets();
666
+ export const hideTimestamp = () => defaultLogger.hideTimestamp();
667
+ export const showTimestamp = () => defaultLogger.showTimestamp();
668
+ export const hideLocation = () => defaultLogger.hideLocation();
669
+ export const showLocation = () => defaultLogger.showLocation();
670
+ export const hideBadges = () => defaultLogger.hideBadges();
671
+ export const showBadges = () => defaultLogger.showBadges();
672
+ export const component = (name) => defaultLogger.component(name);
673
+ export const api = (name) => defaultLogger.api(name);
674
+ export const scope = (name) => defaultLogger.scope(name);
675
+ export const customize = (overrides) => defaultLogger.customize(overrides);
676
+ export const styles = () => defaultLogger.styles();
677
+ // Re-export handlers and utilities for backward compatibility
678
+ export { FileLogHandler, RemoteLogHandler, AnalyticsLogHandler, ExportLogHandler } from './handlers/index.js';
679
+ export { StyleBuilder, StylePresets as Styles } from './styling/index.js';
680
+ export { ScopedLogger, APILogger, ComponentLogger } from './ScopedLogger.js';