@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/src/Logger.ts CHANGED
@@ -20,7 +20,8 @@ import type {
20
20
  import {
21
21
  parseStackTrace,
22
22
  formatTimestamp,
23
- createStyledOutput
23
+ createStyledOutput,
24
+ setupThemeChangeListener
24
25
  } from './utils/index.js';
25
26
 
26
27
  // Styling imports
@@ -32,6 +33,11 @@ import {
32
33
  StyleBuilder
33
34
  } from './styling/index.js';
34
35
 
36
+ // Smart presets and scoped loggers
37
+ import { getSmartPreset, getAvailablePresets, hasPreset } from './styling/SmartPresets.js';
38
+ import { ScopedLogger, APILogger, ComponentLogger } from './ScopedLogger.js';
39
+ import { createLogStyleBuilder } from './styling/LogStyleBuilder.js';
40
+
35
41
  // Handler imports
36
42
  import { ExportLogHandler } from './handlers/index.js';
37
43
 
@@ -57,6 +63,12 @@ export class Logger {
57
63
  private groupDepth: number = 0;
58
64
  private exportHandler?: ExportLogHandler;
59
65
  private cliProcessor?: CommandProcessor;
66
+ private themeChangeListener?: (() => void) | null;
67
+ private displaySettings = {
68
+ showTimestamp: true,
69
+ showLocation: true,
70
+ showBadges: true
71
+ };
60
72
 
61
73
  /**
62
74
  * Creates a new Logger instance
@@ -75,6 +87,31 @@ export class Logger {
75
87
 
76
88
  // Initialize CLI processor
77
89
  this.cliProcessor = createDefaultCLI();
90
+
91
+ // Set up theme change listener if auto-detection is enabled
92
+ if (this.config.autoDetectTheme) {
93
+ this.setupAutoThemeDetection();
94
+ }
95
+ }
96
+
97
+ // ===== PRIVATE HELPER METHODS =====
98
+
99
+ /**
100
+ * Sets up automatic theme detection with change listener
101
+ */
102
+ private setupAutoThemeDetection(): void {
103
+ // Clean up existing listener if any
104
+ if (this.themeChangeListener) {
105
+ this.themeChangeListener();
106
+ this.themeChangeListener = null;
107
+ }
108
+
109
+ // Set up new listener
110
+ this.themeChangeListener = setupThemeChangeListener((theme) => {
111
+ // Theme changed - logs will automatically use new colors on next call
112
+ // No need to update anything as colors are resolved dynamically
113
+ this.debug(`DevTools theme changed to: ${theme}`);
114
+ });
78
115
  }
79
116
 
80
117
  // ===== CONFIGURATION METHODS =====
@@ -90,7 +127,18 @@ export class Logger {
90
127
  * Update configuration
91
128
  */
92
129
  updateConfig(updates: Partial<LoggerConfig>): void {
130
+ const previousAutoDetect = this.config.autoDetectTheme;
93
131
  this.config = { ...this.config, ...updates };
132
+
133
+ // Handle auto-detection changes
134
+ if (updates.autoDetectTheme !== undefined && updates.autoDetectTheme !== previousAutoDetect) {
135
+ if (updates.autoDetectTheme) {
136
+ this.setupAutoThemeDetection();
137
+ } else if (this.themeChangeListener) {
138
+ this.themeChangeListener();
139
+ this.themeChangeListener = null;
140
+ }
141
+ }
94
142
  }
95
143
 
96
144
  /**
@@ -111,6 +159,13 @@ export class Logger {
111
159
  * Sets the logger theme
112
160
  */
113
161
  setTheme(theme: ThemeVariant): void {
162
+ // First check if it's a smart preset
163
+ if (hasPreset(theme)) {
164
+ this.preset(theme);
165
+ return;
166
+ }
167
+
168
+ // Fallback to old theme system
114
169
  if (theme in THEME_PRESETS) {
115
170
  LEVEL_STYLES = (THEME_PRESETS as any)[theme];
116
171
  this.config.theme = theme;
@@ -123,7 +178,7 @@ export class Logger {
123
178
 
124
179
  this.success(`Theme changed to: ${theme}`);
125
180
  } else {
126
- this.error(`Invalid theme: ${theme}. Available themes:`, Object.keys(THEME_PRESETS));
181
+ this.error(`Invalid theme: ${theme}. Available:`, [...getAvailablePresets(), ...Object.keys(THEME_PRESETS)]);
127
182
  }
128
183
  }
129
184
 
@@ -139,22 +194,172 @@ export class Logger {
139
194
  * Reset logger to default configuration
140
195
  */
141
196
  resetConfig(): void {
197
+ // Clean up theme listener
198
+ if (this.themeChangeListener) {
199
+ this.themeChangeListener();
200
+ this.themeChangeListener = null;
201
+ }
202
+
142
203
  this.config = { ...DEFAULT_CONFIG };
143
204
  LEVEL_STYLES = THEME_PRESETS.default;
205
+
206
+ // Re-setup auto theme detection if enabled in default config
207
+ if (this.config.autoDetectTheme) {
208
+ this.setupAutoThemeDetection();
209
+ }
210
+
144
211
  this.success('Logger configuration reset to defaults');
145
212
  }
146
213
 
147
- // ===== SCOPED LOGGER =====
214
+ /**
215
+ * Cleanup method to remove event listeners and free resources
216
+ */
217
+ cleanup(): void {
218
+ if (this.themeChangeListener) {
219
+ this.themeChangeListener();
220
+ this.themeChangeListener = null;
221
+ }
222
+ }
223
+
224
+ // ===== SIMPLIFIED API =====
225
+
226
+ /**
227
+ * Apply a smart preset - works perfectly out-of-the-box
228
+ */
229
+ preset(name: string): void {
230
+ if (!hasPreset(name)) {
231
+ this.error(`Unknown preset: ${name}. Available presets:`, getAvailablePresets());
232
+ return;
233
+ }
234
+
235
+ const presetConfig = getSmartPreset(name);
236
+ if (presetConfig) {
237
+ // Apply the smart preset configuration
238
+ this.displaySettings.showTimestamp = presetConfig.timestamp?.show ?? true;
239
+ this.displaySettings.showLocation = presetConfig.location?.show ?? true;
240
+
241
+ // Store the preset config for use in createStyledOutput
242
+ (this as any)._activePreset = presetConfig;
243
+ (this as any)._activePresetName = name;
244
+
245
+ this.success(`Applied preset: ${name}`);
246
+ }
247
+ }
248
+
249
+ /**
250
+ * List available presets
251
+ */
252
+ presets(): string[] {
253
+ return getAvailablePresets();
254
+ }
255
+
256
+ // ===== TOGGLE METHODS =====
257
+
258
+ /**
259
+ * Hide timestamp in logs
260
+ */
261
+ hideTimestamp(): void {
262
+ this.displaySettings.showTimestamp = false;
263
+ this.success('Timestamp hidden');
264
+ }
265
+
266
+ /**
267
+ * Show timestamp in logs
268
+ */
269
+ showTimestamp(): void {
270
+ this.displaySettings.showTimestamp = true;
271
+ this.success('Timestamp shown');
272
+ }
273
+
274
+ /**
275
+ * Hide location info in logs
276
+ */
277
+ hideLocation(): void {
278
+ this.displaySettings.showLocation = false;
279
+ this.success('Location info hidden');
280
+ }
281
+
282
+ /**
283
+ * Show location info in logs
284
+ */
285
+ showLocation(): void {
286
+ this.displaySettings.showLocation = true;
287
+ this.success('Location info shown');
288
+ }
289
+
290
+ /**
291
+ * Hide badges in logs
292
+ */
293
+ hideBadges(): void {
294
+ this.displaySettings.showBadges = false;
295
+ this.success('Badges hidden');
296
+ }
297
+
298
+ /**
299
+ * Show badges in logs
300
+ */
301
+ showBadges(): void {
302
+ this.displaySettings.showBadges = true;
303
+ this.success('Badges shown');
304
+ }
305
+
306
+ // ===== SCOPED LOGGERS =====
307
+
308
+ /**
309
+ * Create a component logger with automatic styling
310
+ */
311
+ component(name: string): ComponentLogger {
312
+ return new ComponentLogger(this, name);
313
+ }
314
+
315
+ /**
316
+ * Create an API logger with automatic badges
317
+ */
318
+ api(name: string): APILogger {
319
+ return new APILogger(this, name);
320
+ }
321
+
322
+ /**
323
+ * Create a general scoped logger with badges support
324
+ */
325
+ scope(name: string): ScopedLogger {
326
+ return new ScopedLogger(this, name);
327
+ }
328
+
329
+ // ===== SIMPLE CUSTOMIZATION =====
330
+
331
+ /**
332
+ * Simple customization with minimal configuration
333
+ */
334
+ customize(overrides: {
335
+ message?: { color?: string; font?: string; size?: string };
336
+ timestamp?: { show?: boolean; color?: string };
337
+ location?: { show?: boolean; color?: string };
338
+ level?: { uppercase?: boolean; style?: string };
339
+ prefix?: { show?: boolean; style?: string };
340
+ spacing?: 'compact' | 'normal' | 'spacious';
341
+ }): void {
342
+ // Apply simple overrides
343
+ if (overrides.timestamp?.show !== undefined) {
344
+ this.displaySettings.showTimestamp = overrides.timestamp.show;
345
+ }
346
+ if (overrides.location?.show !== undefined) {
347
+ this.displaySettings.showLocation = overrides.location.show;
348
+ }
349
+ if (overrides.prefix?.show !== undefined) {
350
+ // Will be handled when we integrate with preset system
351
+ }
352
+
353
+ // Store customization for use in createStyledOutput
354
+ (this as any)._customization = overrides;
355
+ this.success('Customization applied');
356
+ }
148
357
 
149
358
  /**
150
- * Creates a scoped logger with a specific prefix
359
+ * Access advanced styling API (for power users)
151
360
  */
152
- createScopedLogger(prefix: string): Logger {
153
- const scopedLogger = new Logger(this.config);
154
- scopedLogger.scopedPrefix = prefix;
155
- scopedLogger.handlers = [...this.handlers];
156
- scopedLogger.exportHandler = this.exportHandler;
157
- return scopedLogger;
361
+ styles(): any {
362
+ return createLogStyleBuilder(this);
158
363
  }
159
364
 
160
365
  // ===== HANDLER MANAGEMENT =====
@@ -202,7 +407,7 @@ export class Logger {
202
407
  /**
203
408
  * Core logging method that handles styling and formatting
204
409
  */
205
- private log(level: LogLevel, ...args: any[]): void {
410
+ protected log(level: LogLevel, ...args: any[]): void {
206
411
  if (!this.shouldLog(level)) return;
207
412
 
208
413
  const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
@@ -210,8 +415,15 @@ export class Logger {
210
415
  const message = args.length > 0 ? String(args[0]) : '';
211
416
  const additionalArgs = args.slice(1);
212
417
 
213
- // Create styled output
214
- const [format, ...styles] = createStyledOutput(level, LEVEL_STYLES, prefix, message, stackInfo);
418
+ // Create styled output with theme detection and display settings
419
+ const [format, ...styles] = createStyledOutput(
420
+ level,
421
+ LEVEL_STYLES,
422
+ prefix,
423
+ message,
424
+ this.displaySettings.showLocation ? stackInfo : null,
425
+ this.config.autoDetectTheme
426
+ );
215
427
 
216
428
  // Add group indentation
217
429
  const groupIndent = ' '.repeat(this.groupDepth);
@@ -286,7 +498,14 @@ export class Logger {
286
498
  const additionalArgs = args.slice(1);
287
499
 
288
500
  // Handle success as special case - use info level with success styling
289
- const [format, ...styles] = createStyledOutput('info', LEVEL_STYLES, prefix, message, stackInfo);
501
+ const [format, ...styles] = createStyledOutput(
502
+ 'info',
503
+ LEVEL_STYLES,
504
+ prefix,
505
+ message,
506
+ this.displaySettings.showLocation ? stackInfo : null,
507
+ this.config.autoDetectTheme
508
+ );
290
509
 
291
510
  // Override with success styling
292
511
  const successStyle = LEVEL_STYLES.success;
@@ -580,7 +799,6 @@ export const groupEnd = () => defaultLogger.groupEnd();
580
799
  export const time = (label: string) => defaultLogger.time(label);
581
800
  export const timeEnd = (label: string) => defaultLogger.timeEnd(label);
582
801
  export const setGlobalPrefix = (prefix: string) => defaultLogger.setGlobalPrefix(prefix);
583
- export const createScopedLogger = (prefix: string) => defaultLogger.createScopedLogger(prefix);
584
802
  export const setVerbosity = (level: Verbosity) => defaultLogger.setVerbosity(level);
585
803
  export const addHandler = (handler: ILogHandler) => defaultLogger.addHandler(handler);
586
804
  export const setTheme = (theme: ThemeVariant) => defaultLogger.setTheme(theme);
@@ -591,7 +809,24 @@ export const logWithSVG = (message: string, svgContent?: string, options?: Style
591
809
  export const logAnimated = (message: string, duration?: number) =>
592
810
  defaultLogger.logAnimated(message, duration);
593
811
  export const cli = (command: string) => defaultLogger.cli(command);
812
+ export const cleanup = () => defaultLogger.cleanup();
813
+
814
+ // Simplified API exports
815
+ export const preset = (name: string) => defaultLogger.preset(name);
816
+ export const presets = () => defaultLogger.presets();
817
+ export const hideTimestamp = () => defaultLogger.hideTimestamp();
818
+ export const showTimestamp = () => defaultLogger.showTimestamp();
819
+ export const hideLocation = () => defaultLogger.hideLocation();
820
+ export const showLocation = () => defaultLogger.showLocation();
821
+ export const hideBadges = () => defaultLogger.hideBadges();
822
+ export const showBadges = () => defaultLogger.showBadges();
823
+ export const component = (name: string) => defaultLogger.component(name);
824
+ export const api = (name: string) => defaultLogger.api(name);
825
+ export const scope = (name: string) => defaultLogger.scope(name);
826
+ export const customize = (overrides: any) => defaultLogger.customize(overrides);
827
+ export const styles = () => defaultLogger.styles();
594
828
 
595
829
  // Re-export handlers and utilities for backward compatibility
596
830
  export { FileLogHandler, RemoteLogHandler, AnalyticsLogHandler, ExportLogHandler } from './handlers/index.js';
597
- export { StyleBuilder, StylePresets as Styles } from './styling/index.js';
831
+ export { StyleBuilder, StylePresets as Styles } from './styling/index.js';
832
+ export { ScopedLogger, APILogger, ComponentLogger } from './ScopedLogger.js';
@@ -0,0 +1,262 @@
1
+ /**
2
+ * @fileoverview ScopedLogger with badges and contextual logging
3
+ */
4
+
5
+ import { Logger } from './Logger.js';
6
+ import type { LoggerConfig, LogLevel, Verbosity, BannerType, StyleOptions, ILogHandler } from './types/index.js';
7
+
8
+ /**
9
+ * Enhanced scoped logger with badges and simplified API
10
+ */
11
+ export class ScopedLogger extends Logger {
12
+ private parentLogger: Logger;
13
+ private scopeName: string;
14
+ private badgeList: string[] = [];
15
+ private contextStack: string[] = [];
16
+
17
+ constructor(parentLogger: Logger, scopeName: string, config?: Partial<LoggerConfig>) {
18
+ // Initialize with parent's config plus any overrides
19
+ super({ ...parentLogger.getConfig(), ...config });
20
+ this.parentLogger = parentLogger;
21
+ this.scopeName = scopeName;
22
+
23
+ // Inherit parent's handlers
24
+ const parentHandlers = parentLogger.getHandlers();
25
+ parentHandlers.forEach(handler => this.addHandler(handler));
26
+ }
27
+
28
+ /**
29
+ * Add badges to this scoped logger
30
+ */
31
+ badges(badges: string[]): ScopedLogger {
32
+ this.badgeList = [...badges];
33
+ return this;
34
+ }
35
+
36
+ /**
37
+ * Add a single badge
38
+ */
39
+ badge(badge: string): ScopedLogger {
40
+ if (!this.badgeList.includes(badge)) {
41
+ this.badgeList.push(badge);
42
+ }
43
+ return this;
44
+ }
45
+
46
+ /**
47
+ * Remove badges
48
+ */
49
+ clearBadges(): ScopedLogger {
50
+ this.badgeList = [];
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Set style preset for this scoped logger
56
+ */
57
+ style(presetName: string): ScopedLogger {
58
+ this.setTheme(presetName as any); // Will be updated when we implement presets
59
+ return this;
60
+ }
61
+
62
+ /**
63
+ * Create a temporary context that gets automatically cleaned up
64
+ */
65
+ context(contextName: string): ContextLogger {
66
+ return new ContextLogger(this, contextName);
67
+ }
68
+
69
+ /**
70
+ * Override core logging to include badges
71
+ */
72
+ protected log(level: LogLevel, ...args: any[]): void {
73
+ // Build the enhanced message with badges
74
+ const badges = this.getBadgeString();
75
+ const scopePrefix = this.getScopePrefix();
76
+
77
+ let enhancedMessage = '';
78
+ if (badges) enhancedMessage += badges + ' ';
79
+ if (scopePrefix) enhancedMessage += `[${scopePrefix}] `;
80
+
81
+ if (args.length > 0) {
82
+ enhancedMessage += String(args[0]);
83
+ // Replace the first argument with our enhanced message
84
+ args[0] = enhancedMessage;
85
+ }
86
+
87
+ // Call parent's log method
88
+ super.log(level, ...args);
89
+ }
90
+
91
+ /**
92
+ * Get formatted badge string
93
+ */
94
+ private getBadgeString(): string {
95
+ if (this.badgeList.length === 0) return '';
96
+ return this.badgeList.map(badge => `[${badge}]`).join('');
97
+ }
98
+
99
+ /**
100
+ * Get scope prefix (includes context stack)
101
+ */
102
+ private getScopePrefix(): string {
103
+ const parts = [this.scopeName, ...this.contextStack].filter(Boolean);
104
+ return parts.join(':');
105
+ }
106
+
107
+ /**
108
+ * Internal method to push context
109
+ */
110
+ _pushContext(context: string): void {
111
+ this.contextStack.push(context);
112
+ }
113
+
114
+ /**
115
+ * Internal method to pop context
116
+ */
117
+ _popContext(): void {
118
+ this.contextStack.pop();
119
+ }
120
+ }
121
+
122
+ /**
123
+ * API-specific scoped logger with common API badges
124
+ */
125
+ export class APILogger extends ScopedLogger {
126
+ constructor(parentLogger: Logger, apiName: string, config?: Partial<LoggerConfig>) {
127
+ super(parentLogger, `API:${apiName}`, config);
128
+ this.badge('API');
129
+ }
130
+
131
+ /**
132
+ * Log slow operations
133
+ */
134
+ slow(message: string, duration?: number): void {
135
+ this.badge('SLOW');
136
+ const msg = duration ? `${message} (${duration}ms)` : message;
137
+ this.warn(msg);
138
+ }
139
+
140
+ /**
141
+ * Log rate limiting
142
+ */
143
+ rateLimit(message: string): void {
144
+ this.badge('RATE_LIMIT');
145
+ this.warn(message);
146
+ }
147
+
148
+ /**
149
+ * Log authentication issues
150
+ */
151
+ auth(message: string): void {
152
+ this.badge('AUTH');
153
+ this.error(message);
154
+ }
155
+
156
+ /**
157
+ * Log deprecation warnings
158
+ */
159
+ deprecated(message: string): void {
160
+ this.badge('DEPRECATED');
161
+ this.warn(message);
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Component-specific scoped logger
167
+ */
168
+ export class ComponentLogger extends ScopedLogger {
169
+ constructor(parentLogger: Logger, componentName: string, config?: Partial<LoggerConfig>) {
170
+ super(parentLogger, componentName, config);
171
+ this.badge('COMPONENT');
172
+ }
173
+
174
+ /**
175
+ * Log lifecycle events
176
+ */
177
+ lifecycle(event: string, message?: string): void {
178
+ this.badge('LIFECYCLE');
179
+ const msg = message ? `${event}: ${message}` : event;
180
+ this.info(msg);
181
+ }
182
+
183
+ /**
184
+ * Log state changes
185
+ */
186
+ stateChange(from: string, to: string, data?: any): void {
187
+ this.badge('STATE');
188
+ const msg = `${from} → ${to}`;
189
+ if (data) {
190
+ this.info(msg, data);
191
+ } else {
192
+ this.info(msg);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Log prop changes
198
+ */
199
+ propsChange(changes: Record<string, any>): void {
200
+ this.badge('PROPS');
201
+ this.debug('Props changed:', changes);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Temporary context logger that auto-cleans up
207
+ */
208
+ export class ContextLogger {
209
+ private parentLogger: ScopedLogger;
210
+ private contextName: string;
211
+
212
+ constructor(parentLogger: ScopedLogger, contextName: string) {
213
+ this.parentLogger = parentLogger;
214
+ this.contextName = contextName;
215
+ }
216
+
217
+ /**
218
+ * Run a function with this context active
219
+ */
220
+ run<T>(fn: () => T): T {
221
+ this.parentLogger._pushContext(this.contextName);
222
+ try {
223
+ return fn();
224
+ } finally {
225
+ this.parentLogger._popContext();
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Run an async function with this context active
231
+ */
232
+ async runAsync<T>(fn: () => Promise<T>): Promise<T> {
233
+ this.parentLogger._pushContext(this.contextName);
234
+ try {
235
+ return await fn();
236
+ } finally {
237
+ this.parentLogger._popContext();
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Start the context (manual mode)
243
+ */
244
+ start(): void {
245
+ this.parentLogger._pushContext(this.contextName);
246
+ }
247
+
248
+ /**
249
+ * End the context (manual mode)
250
+ */
251
+ end(): void {
252
+ this.parentLogger._popContext();
253
+ }
254
+
255
+ // Delegate logging methods to parent with context
256
+ debug(...args: any[]): void { this.parentLogger.debug(...args); }
257
+ info(...args: any[]): void { this.parentLogger.info(...args); }
258
+ warn(...args: any[]): void { this.parentLogger.warn(...args); }
259
+ error(...args: any[]): void { this.parentLogger.error(...args); }
260
+ success(...args: any[]): void { this.parentLogger.success(...args); }
261
+ critical(...args: any[]): void { this.parentLogger.critical(...args); }
262
+ }