@mks2508/better-logger 5.0.1 → 5.0.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 (310) hide show
  1. package/dist/Logger.d.ts +976 -0
  2. package/dist/Logger.d.ts.map +1 -0
  3. package/dist/ScopedLogger.d.ts +74 -0
  4. package/dist/ScopedLogger.d.ts.map +1 -0
  5. package/dist/chunks/Logger-CKqzXDh3.js +2 -0
  6. package/dist/chunks/Logger-CKqzXDh3.js.map +1 -0
  7. package/dist/chunks/Logger-D_vuKP4l.js +4511 -0
  8. package/dist/chunks/Logger-D_vuKP4l.js.map +1 -0
  9. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
  10. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
  11. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
  12. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
  13. package/dist/chunks/cli-module-B-njrTWb.js +2 -0
  14. package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
  15. package/dist/chunks/cli-module-Cx7qotPY.js +390 -0
  16. package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
  17. package/dist/chunks/color-converter-CCSQRztd.js +2 -0
  18. package/dist/chunks/color-converter-CCSQRztd.js.map +1 -0
  19. package/dist/chunks/color-converter-_Xdmsy7E.js +462 -0
  20. package/dist/chunks/color-converter-_Xdmsy7E.js.map +1 -0
  21. package/dist/chunks/environment-C1xxvc8l.js +1127 -0
  22. package/dist/chunks/environment-C1xxvc8l.js.map +1 -0
  23. package/dist/chunks/environment-Cprkw3g9.js +4 -0
  24. package/dist/chunks/environment-Cprkw3g9.js.map +1 -0
  25. package/dist/chunks/formatting-DMJxYq9o.js +380 -0
  26. package/dist/chunks/formatting-DMJxYq9o.js.map +1 -0
  27. package/dist/chunks/formatting-DpKxCsXq.js +2 -0
  28. package/dist/chunks/formatting-DpKxCsXq.js.map +1 -0
  29. package/dist/cli/CommandProcessor.d.ts +100 -0
  30. package/dist/cli/CommandProcessor.d.ts.map +1 -0
  31. package/dist/cli/commands/ConfigCommand.d.ts +14 -0
  32. package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
  33. package/dist/cli/commands/ExportCommand.d.ts +48 -0
  34. package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
  35. package/dist/cli/commands/HistoryCommand.d.ts +47 -0
  36. package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
  37. package/dist/cli/commands/StatusCommand.d.ts +30 -0
  38. package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
  39. package/dist/cli/commands/ThemeCommand.d.ts +30 -0
  40. package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
  41. package/dist/cli/help.d.ts +12 -0
  42. package/dist/cli/help.d.ts.map +1 -0
  43. package/dist/cli/index.d.ts +15 -0
  44. package/dist/cli/index.d.ts.map +1 -0
  45. package/{src/cli-module.ts → dist/cli-module.d.ts} +2 -8
  46. package/dist/cli-module.d.ts.map +1 -0
  47. package/dist/cli-primitives/box.d.ts +11 -0
  48. package/dist/cli-primitives/box.d.ts.map +1 -0
  49. package/dist/cli-primitives/cli-table.d.ts +11 -0
  50. package/dist/cli-primitives/cli-table.d.ts.map +1 -0
  51. package/dist/cli-primitives/divider.d.ts +11 -0
  52. package/dist/cli-primitives/divider.d.ts.map +1 -0
  53. package/dist/cli-primitives/header.d.ts +12 -0
  54. package/dist/cli-primitives/header.d.ts.map +1 -0
  55. package/{src/cli-primitives/index.ts → dist/cli-primitives/index.d.ts} +1 -1
  56. package/dist/cli-primitives/index.d.ts.map +1 -0
  57. package/dist/cli-primitives/server-fallback.d.ts +25 -0
  58. package/dist/cli-primitives/server-fallback.d.ts.map +1 -0
  59. package/dist/cli-primitives/spinner.d.ts +47 -0
  60. package/dist/cli-primitives/spinner.d.ts.map +1 -0
  61. package/dist/cli-primitives/step.d.ts +11 -0
  62. package/dist/cli-primitives/step.d.ts.map +1 -0
  63. package/dist/cli.cjs +2 -0
  64. package/dist/cli.cjs.map +1 -0
  65. package/dist/cli.js +12 -0
  66. package/dist/cli.js.map +1 -0
  67. package/dist/constants.d.ts +235 -0
  68. package/dist/constants.d.ts.map +1 -0
  69. package/dist/core.cjs +2 -0
  70. package/dist/core.cjs.map +1 -0
  71. package/dist/core.d.ts +127 -0
  72. package/dist/core.d.ts.map +1 -0
  73. package/dist/core.js +291 -0
  74. package/dist/core.js.map +1 -0
  75. package/dist/example.d.ts +18 -0
  76. package/dist/example.d.ts.map +1 -0
  77. package/dist/exports-module.d.ts +196 -0
  78. package/dist/exports-module.d.ts.map +1 -0
  79. package/dist/exports.cjs +2 -0
  80. package/dist/exports.cjs.map +1 -0
  81. package/dist/exports.js +238 -0
  82. package/dist/exports.js.map +1 -0
  83. package/dist/handlers/AnalyticsLogHandler.d.ts +8 -0
  84. package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  85. package/dist/handlers/ExportLogHandler.d.ts +100 -0
  86. package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
  87. package/dist/handlers/FileLogHandler.d.ts +33 -0
  88. package/dist/handlers/FileLogHandler.d.ts.map +1 -0
  89. package/dist/handlers/RemoteLogHandler.d.ts +11 -0
  90. package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
  91. package/{src/handlers/index.ts → dist/handlers/index.d.ts} +2 -2
  92. package/dist/handlers/index.d.ts.map +1 -0
  93. package/dist/hooks/HookManager.d.ts +21 -0
  94. package/dist/hooks/HookManager.d.ts.map +1 -0
  95. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
  96. package/dist/hooks/index.d.ts.map +1 -0
  97. package/dist/index.cjs +2 -0
  98. package/dist/index.cjs.map +1 -0
  99. package/dist/index.d.ts +161 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +627 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/main.d.ts +2 -0
  104. package/dist/main.d.ts.map +1 -0
  105. package/dist/serializers/SerializerRegistry.d.ts +16 -0
  106. package/dist/serializers/SerializerRegistry.d.ts.map +1 -0
  107. package/{src/serializers/index.ts → dist/serializers/index.d.ts} +1 -0
  108. package/dist/serializers/index.d.ts.map +1 -0
  109. package/dist/styling/LogStyleBuilder.d.ts +146 -0
  110. package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
  111. package/dist/styling/SemanticStyles.d.ts +178 -0
  112. package/dist/styling/SemanticStyles.d.ts.map +1 -0
  113. package/dist/styling/SmartPresets.d.ts +22 -0
  114. package/dist/styling/SmartPresets.d.ts.map +1 -0
  115. package/dist/styling/StyleBuilder.d.ts +140 -0
  116. package/dist/styling/StyleBuilder.d.ts.map +1 -0
  117. package/dist/styling/StyleCache.d.ts +42 -0
  118. package/dist/styling/StyleCache.d.ts.map +1 -0
  119. package/dist/styling/banners.d.ts +42 -0
  120. package/dist/styling/banners.d.ts.map +1 -0
  121. package/dist/styling/index.d.ts +10 -0
  122. package/dist/styling/index.d.ts.map +1 -0
  123. package/dist/styling/themes.d.ts +7 -0
  124. package/dist/styling/themes.d.ts.map +1 -0
  125. package/dist/styling-module.d.ts +178 -0
  126. package/dist/styling-module.d.ts.map +1 -0
  127. package/dist/styling.cjs +2 -0
  128. package/dist/styling.cjs.map +1 -0
  129. package/dist/styling.js +146 -0
  130. package/dist/styling.js.map +1 -0
  131. package/dist/terminal/color-converter.d.ts +73 -0
  132. package/dist/terminal/color-converter.d.ts.map +1 -0
  133. package/dist/terminal/formatter.d.ts +20 -0
  134. package/dist/terminal/formatter.d.ts.map +1 -0
  135. package/dist/terminal/terminal-renderer.d.ts +77 -0
  136. package/dist/terminal/terminal-renderer.d.ts.map +1 -0
  137. package/dist/transports/ConsoleTransport.d.ts +9 -0
  138. package/dist/transports/ConsoleTransport.d.ts.map +1 -0
  139. package/dist/transports/FileTransport.d.ts +15 -0
  140. package/dist/transports/FileTransport.d.ts.map +1 -0
  141. package/dist/transports/HttpTransport.d.ts +16 -0
  142. package/dist/transports/HttpTransport.d.ts.map +1 -0
  143. package/dist/transports/TransportManager.d.ts +14 -0
  144. package/dist/transports/TransportManager.d.ts.map +1 -0
  145. package/{src/transports/index.ts → dist/transports/index.d.ts} +1 -0
  146. package/dist/transports/index.d.ts.map +1 -0
  147. package/{src/types/core.ts → dist/types/core.d.ts} +25 -62
  148. package/dist/types/core.d.ts.map +1 -0
  149. package/{src/types/handlers.ts → dist/types/handlers.d.ts} +5 -15
  150. package/dist/types/handlers.d.ts.map +1 -0
  151. package/{src/types/hooks.ts → dist/types/hooks.d.ts} +3 -12
  152. package/dist/types/hooks.d.ts.map +1 -0
  153. package/dist/types/index.d.ts +11 -0
  154. package/dist/types/index.d.ts.map +1 -0
  155. package/{src/types/serializers.ts → dist/types/serializers.d.ts} +1 -6
  156. package/dist/types/serializers.d.ts.map +1 -0
  157. package/{src/types/transports.ts → dist/types/transports.d.ts} +2 -7
  158. package/dist/types/transports.d.ts.map +1 -0
  159. package/dist/utils/adapter.d.ts +48 -0
  160. package/dist/utils/adapter.d.ts.map +1 -0
  161. package/dist/utils/ansi-colors.d.ts +156 -0
  162. package/dist/utils/ansi-colors.d.ts.map +1 -0
  163. package/dist/utils/environment-detector.d.ts +45 -0
  164. package/dist/utils/environment-detector.d.ts.map +1 -0
  165. package/dist/utils/environment.d.ts +47 -0
  166. package/dist/utils/environment.d.ts.map +1 -0
  167. package/dist/utils/formatting.d.ts +58 -0
  168. package/dist/utils/formatting.d.ts.map +1 -0
  169. package/dist/utils/index.d.ts +8 -0
  170. package/dist/utils/index.d.ts.map +1 -0
  171. package/dist/utils/opentui-detection.d.ts +34 -0
  172. package/dist/utils/opentui-detection.d.ts.map +1 -0
  173. package/dist/utils/output.d.ts +46 -0
  174. package/dist/utils/output.d.ts.map +1 -0
  175. package/dist/utils/stackTrace.d.ts +6 -0
  176. package/dist/utils/stackTrace.d.ts.map +1 -0
  177. package/dist/utils/timestamps.d.ts +20 -0
  178. package/dist/utils/timestamps.d.ts.map +1 -0
  179. package/{src/writers/BufferWriter.ts → dist/writers/BufferWriter.d.ts} +16 -77
  180. package/dist/writers/BufferWriter.d.ts.map +1 -0
  181. package/{src/writers/index.ts → dist/writers/index.d.ts} +1 -1
  182. package/dist/writers/index.d.ts.map +1 -0
  183. package/package.json +5 -1
  184. package/.claude/settings.local.json +0 -48
  185. package/.github/workflows/ci-quality.yml +0 -357
  186. package/.github/workflows/docs-demo.yml +0 -119
  187. package/.github/workflows/releases-core.yml +0 -512
  188. package/.github/workflows/releases-full.yml +0 -582
  189. package/.github/workflows-backup/ci.yml +0 -221
  190. package/.github/workflows-backup/nightly.yml +0 -196
  191. package/.github/workflows-backup/release-optimized.yml +0 -373
  192. package/.github/workflows-backup/release.yml +0 -269
  193. package/.release-notes-0.2.0.md +0 -129
  194. package/.yamllint +0 -28
  195. package/CHANGELOG.json +0 -1120
  196. package/CHANGELOG.md +0 -209
  197. package/CLAUDE.md +0 -217
  198. package/demo.html +0 -847
  199. package/docs/API.md +0 -918
  200. package/docs/CORE.md +0 -264
  201. package/docs/DEVELOPMENT.md +0 -731
  202. package/docs/EXPORTS.md +0 -467
  203. package/docs/PACKAGES.md +0 -244
  204. package/docs/STYLING.md +0 -405
  205. package/docs/_config.yml +0 -36
  206. package/docs/index.md +0 -179
  207. package/examples/README.md +0 -208
  208. package/examples/basic-logging.js +0 -75
  209. package/examples/data-export.js +0 -234
  210. package/examples/package.json +0 -16
  211. package/examples/performance-timing.js +0 -170
  212. package/examples/simplified-api.js +0 -124
  213. package/examples/styling-themes.js +0 -207
  214. package/index.html +0 -358
  215. package/packages/core/package.json +0 -57
  216. package/packages/exports/package.json +0 -41
  217. package/packages/nodejs-opentui/README.md +0 -232
  218. package/packages/nodejs-opentui/package.json +0 -72
  219. package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
  220. package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
  221. package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
  222. package/packages/nodejs-opentui/src/index.ts +0 -133
  223. package/packages/nodejs-opentui/src/types.ts +0 -158
  224. package/packages/nodejs-opentui/tsconfig.json +0 -20
  225. package/packages/styling/package.json +0 -41
  226. package/playground/demo-all.ts +0 -95
  227. package/playground/demo-box.ts +0 -85
  228. package/playground/demo-levels.ts +0 -56
  229. package/playground/demo-real-world.ts +0 -98
  230. package/playground/demo-spinner.ts +0 -77
  231. package/playground/demo-steps.ts +0 -72
  232. package/playground/demo-table.ts +0 -83
  233. package/project-utils/README.md +0 -172
  234. package/project-utils/auto-release-gemini.ts +0 -1193
  235. package/project-utils/auto-release-ui.ts +0 -1329
  236. package/project-utils/commit-generator.ts +0 -1385
  237. package/project-utils/commit-ui.ts +0 -264
  238. package/project-utils/git-utils.ts +0 -199
  239. package/project-utils/github-release-manager.ts +0 -466
  240. package/project-utils/project-config.ts +0 -260
  241. package/project-utils/prompt-templates.js +0 -345
  242. package/project-utils/prompt-templates.ts +0 -422
  243. package/project-utils/version-manager.ts +0 -1078
  244. package/src/Logger.ts +0 -1858
  245. package/src/ScopedLogger.ts +0 -256
  246. package/src/cli/CommandProcessor.ts +0 -248
  247. package/src/cli/commands/ConfigCommand.ts +0 -93
  248. package/src/cli/commands/ExportCommand.ts +0 -276
  249. package/src/cli/commands/HistoryCommand.ts +0 -117
  250. package/src/cli/commands/StatusCommand.ts +0 -112
  251. package/src/cli/commands/ThemeCommand.ts +0 -88
  252. package/src/cli/help.ts +0 -127
  253. package/src/cli/index.ts +0 -71
  254. package/src/cli-primitives/box.ts +0 -86
  255. package/src/cli-primitives/cli-table.ts +0 -62
  256. package/src/cli-primitives/divider.ts +0 -17
  257. package/src/cli-primitives/header.ts +0 -18
  258. package/src/cli-primitives/server-fallback.ts +0 -54
  259. package/src/cli-primitives/spinner.ts +0 -133
  260. package/src/cli-primitives/step.ts +0 -22
  261. package/src/constants.ts +0 -313
  262. package/src/core.ts +0 -397
  263. package/src/example.ts +0 -210
  264. package/src/exports-module.ts +0 -311
  265. package/src/handlers/AnalyticsLogHandler.ts +0 -22
  266. package/src/handlers/ExportLogHandler.ts +0 -610
  267. package/src/handlers/FileLogHandler.ts +0 -169
  268. package/src/handlers/RemoteLogHandler.ts +0 -42
  269. package/src/hooks/HookManager.ts +0 -177
  270. package/src/index.ts +0 -395
  271. package/src/main.ts +0 -196
  272. package/src/serializers/SerializerRegistry.ts +0 -173
  273. package/src/style.css +0 -96
  274. package/src/styling/LogStyleBuilder.ts +0 -355
  275. package/src/styling/SemanticStyles.ts +0 -380
  276. package/src/styling/SmartPresets.ts +0 -288
  277. package/src/styling/StyleBuilder.ts +0 -319
  278. package/src/styling/StyleCache.ts +0 -131
  279. package/src/styling/banners.ts +0 -168
  280. package/src/styling/index.ts +0 -27
  281. package/src/styling/themes.ts +0 -235
  282. package/src/styling-module.ts +0 -244
  283. package/src/terminal/color-converter.ts +0 -315
  284. package/src/terminal/formatter.ts +0 -242
  285. package/src/terminal/terminal-renderer.ts +0 -342
  286. package/src/transports/ConsoleTransport.ts +0 -28
  287. package/src/transports/FileTransport.ts +0 -53
  288. package/src/transports/HttpTransport.ts +0 -56
  289. package/src/transports/TransportManager.ts +0 -130
  290. package/src/types/index.ts +0 -83
  291. package/src/typescript.svg +0 -1
  292. package/src/utils/adapter.ts +0 -291
  293. package/src/utils/ansi-colors.ts +0 -333
  294. package/src/utils/environment-detector.ts +0 -170
  295. package/src/utils/environment.ts +0 -94
  296. package/src/utils/formatting.ts +0 -332
  297. package/src/utils/index.ts +0 -33
  298. package/src/utils/opentui-detection.ts +0 -138
  299. package/src/utils/output.ts +0 -227
  300. package/src/utils/stackTrace.ts +0 -144
  301. package/src/utils/timestamps.ts +0 -80
  302. package/src/vite-env.d.ts +0 -1
  303. package/test-core-browser.html +0 -237
  304. package/test-core-node.js +0 -63
  305. package/tests/test-conflict-resolution.ts +0 -391
  306. package/tests/validate-workflows.sh +0 -131
  307. package/tests/yaml-autofix.sh +0 -146
  308. package/tsconfig.json +0 -50
  309. package/vite.config.ts +0 -256
  310. /package/{public → dist}/vite.svg +0 -0
package/src/constants.ts DELETED
@@ -1,313 +0,0 @@
1
- /**
2
- * @fileoverview Global constants for Advanced Logger
3
- */
4
-
5
- import type { LogLevel, AdaptiveColors, CLILogLevel, Verbosity } from './types/index.js';
6
- import type { LevelStyleConfig } from './utils/index.js';
7
-
8
- /**
9
- * Default configuration values
10
- */
11
- export const DEFAULT_CONFIG = {
12
- verbosity: 'info' as const,
13
- enableColors: true,
14
- enableTimestamps: true,
15
- enableStackTrace: true,
16
- theme: 'default' as const,
17
- bannerType: 'simple' as const,
18
- bufferSize: 1000,
19
- autoDetectTheme: true,
20
- outputFormat: 'auto' as const,
21
- } as const;
22
-
23
- /**
24
- * Basic level styles for core module (minimal CSS styling)
25
- */
26
- export const LEVEL_STYLES: Record<LogLevel | 'success', LevelStyleConfig> = {
27
- debug: {
28
- emoji: '🔍',
29
- label: 'DEBUG',
30
- background: 'linear-gradient(90deg, #6c757d, #495057)',
31
- color: '#ffffff',
32
- border: '1px solid #6c757d',
33
- shadow: '0 2px 4px rgba(108, 117, 125, 0.3)'
34
- },
35
- info: {
36
- emoji: 'ℹ️',
37
- label: 'INFO',
38
- background: 'linear-gradient(90deg, #007bff, #0056b3)',
39
- color: '#ffffff',
40
- border: '1px solid #007bff',
41
- shadow: '0 2px 4px rgba(0, 123, 255, 0.3)'
42
- },
43
- warn: {
44
- emoji: '⚠️',
45
- label: 'WARN',
46
- background: 'linear-gradient(90deg, #ffc107, #e0a800)',
47
- color: '#000000',
48
- border: '1px solid #ffc107',
49
- shadow: '0 2px 4px rgba(255, 193, 7, 0.3)'
50
- },
51
- error: {
52
- emoji: '❌',
53
- label: 'ERROR',
54
- background: 'linear-gradient(90deg, #dc3545, #c82333)',
55
- color: '#ffffff',
56
- border: '1px solid #dc3545',
57
- shadow: '0 2px 4px rgba(220, 53, 69, 0.3)'
58
- },
59
- critical: {
60
- emoji: '🚨',
61
- label: 'CRITICAL',
62
- background: 'linear-gradient(90deg, #8B0000, #FF0000)',
63
- color: '#ffffff',
64
- border: '2px solid #FF0000',
65
- shadow: '0 4px 8px rgba(255, 0, 0, 0.4)'
66
- },
67
- success: {
68
- emoji: '✅',
69
- label: 'SUCCESS',
70
- background: 'linear-gradient(90deg, #28a745, #1e7e34)',
71
- color: '#ffffff',
72
- border: '1px solid #28a745',
73
- shadow: '0 2px 4px rgba(40, 167, 69, 0.3)'
74
- }
75
- } as const;
76
-
77
- /**
78
- * Maximum allowed buffer sizes for performance
79
- */
80
- export const BUFFER_LIMITS = {
81
- MIN_SIZE: 50,
82
- DEFAULT_SIZE: 1000,
83
- MAX_SIZE: 10000,
84
- } as const;
85
-
86
- /**
87
- * Export format definitions with extensions
88
- */
89
- export const EXPORT_FORMATS = {
90
- json: { extension: '.json', mimeType: 'application/json' },
91
- csv: { extension: '.csv', mimeType: 'text/csv' },
92
- markdown: { extension: '.md', mimeType: 'text/markdown' },
93
- plain: { extension: '.txt', mimeType: 'text/plain' },
94
- html: { extension: '.html', mimeType: 'text/html' },
95
- } as const;
96
-
97
- /**
98
- * CLI command definitions
99
- */
100
- export const CLI_COMMANDS = {
101
- config: 'config',
102
- help: 'help',
103
- themes: 'themes',
104
- banners: 'banners',
105
- banner: 'banner',
106
- status: 'status',
107
- reset: 'reset',
108
- demo: 'demo',
109
- export: 'export',
110
- copy: 'copy',
111
- 'buffer-size': 'buffer-size',
112
- 'clear-buffer': 'clear-buffer',
113
- 'buffer-info': 'buffer-info',
114
- } as const;
115
-
116
- /**
117
- * Time parsing constants for relative time filters
118
- */
119
- export const TIME_UNITS = {
120
- ms: 1,
121
- s: 1000,
122
- m: 60 * 1000,
123
- h: 60 * 60 * 1000,
124
- d: 24 * 60 * 60 * 1000,
125
- } as const;
126
-
127
- /**
128
- * Default styling values
129
- */
130
- export const STYLE_DEFAULTS = {
131
- FONT_FAMILY: 'Monaco, Consolas, monospace',
132
- FONT_SIZE: '12px',
133
- BORDER_RADIUS: '4px',
134
- PADDING: '4px 8px',
135
- } as const;
136
-
137
- /**
138
- * Level priority mapping for filtering
139
- */
140
- export const LEVEL_PRIORITIES: Record<LogLevel, number> = {
141
- debug: 0,
142
- info: 1,
143
- warn: 2,
144
- error: 3,
145
- critical: 4,
146
- } as const;
147
-
148
- /**
149
- * Adaptive color configurations for DevTools theme compatibility
150
- */
151
- export const ADAPTIVE_COLORS = {
152
- timestamp: {
153
- light: '#666666',
154
- dark: '#a0a0a0',
155
- },
156
- messageText: {
157
- light: '#2d3748',
158
- dark: '#f7fafc',
159
- },
160
- prefix: {
161
- light: '#2d3748',
162
- dark: '#e2e8f0',
163
- },
164
- prefixBackground: {
165
- light: '#2d3748',
166
- dark: '#4a5568',
167
- },
168
- location: {
169
- light: '#718096',
170
- dark: '#a0aec0',
171
- },
172
- } as const satisfies Record<string, AdaptiveColors>;
173
-
174
- /**
175
- * Presets específicos para diferentes entornos de build
176
- */
177
- export const BUILD_PRESETS = {
178
- /**
179
- * Configuración optimizada para Next.js builds
180
- */
181
- nextjs: {
182
- verbosity: 'info' as const,
183
- enableColors: true,
184
- enableTimestamps: false,
185
- enableStackTrace: false,
186
- autoDetectTheme: false,
187
- outputFormat: 'build' as const,
188
- },
189
-
190
- /**
191
- * Configuración para Webpack builds
192
- */
193
- webpack: {
194
- verbosity: 'info' as const,
195
- enableColors: true,
196
- enableTimestamps: true,
197
- enableStackTrace: false,
198
- autoDetectTheme: false,
199
- outputFormat: 'build' as const,
200
- },
201
-
202
- /**
203
- * Configuración para CI/CD environments
204
- */
205
- ci: {
206
- verbosity: 'info' as const,
207
- enableColors: false,
208
- enableTimestamps: true,
209
- enableStackTrace: true,
210
- autoDetectTheme: false,
211
- outputFormat: 'ci' as const,
212
- },
213
-
214
- /**
215
- * Configuración para desarrollo terminal
216
- */
217
- terminal: {
218
- verbosity: 'debug' as const,
219
- enableColors: true,
220
- enableTimestamps: true,
221
- enableStackTrace: true,
222
- autoDetectTheme: false,
223
- outputFormat: 'ansi' as const,
224
- }
225
- } as const;
226
-
227
- /**
228
- * Mapeo de variables de entorno a presets
229
- */
230
- export const ENVIRONMENT_DETECTION = {
231
- // Next.js detection
232
- isNextJS: typeof process !== 'undefined' && (
233
- process.env.NEXT_RUNTIME ||
234
- process.env.NEXT_PUBLIC_VERCEL_ENV ||
235
- (process.argv && process.argv.some(arg => arg.includes('next')))
236
- ),
237
-
238
- // Webpack detection
239
- isWebpack: typeof process !== 'undefined' && (
240
- process.env.WEBPACK_ENV ||
241
- process.env.WEBPACK_BUILD ||
242
- (process.argv && process.argv.some(arg => arg.includes('webpack')))
243
- ),
244
-
245
- // CI/CD detection
246
- isCI: typeof process !== 'undefined' && (
247
- process.env.CI ||
248
- process.env.GITHUB_ACTIONS ||
249
- process.env.JENKINS_URL ||
250
- process.env.GITLAB_CI ||
251
- process.env.TRAVIS ||
252
- process.env.CIRCLECI
253
- ),
254
-
255
- // Build detection
256
- isBuild: typeof process !== 'undefined' && (
257
- process.env.NODE_ENV === 'production' ||
258
- process.env.BUILD_MODE === 'production' ||
259
- (process.argv && process.argv.some(arg => arg.includes('build')))
260
- ),
261
-
262
- // Terminal with ANSI support
263
- isTerminal: typeof process !== 'undefined' && (
264
- process.stdout?.isTTY === true &&
265
- process.env.TERM !== 'dumb'
266
- )
267
- } as const;
268
-
269
- /**
270
- * Auto-detects the best preset based on current environment
271
- */
272
- export function detectEnvironmentPreset(): keyof typeof BUILD_PRESETS {
273
- if (ENVIRONMENT_DETECTION.isCI) {
274
- return 'ci';
275
- }
276
-
277
- if (ENVIRONMENT_DETECTION.isNextJS) {
278
- return 'nextjs';
279
- }
280
-
281
- if (ENVIRONMENT_DETECTION.isWebpack) {
282
- return 'webpack';
283
- }
284
-
285
- if (ENVIRONMENT_DETECTION.isTerminal) {
286
- return 'terminal';
287
- }
288
-
289
- return 'terminal'; // Default fallback
290
- }
291
-
292
- /**
293
- * Gets the optimal configuration for current environment
294
- */
295
- export function getOptimalConfig() {
296
- const preset = detectEnvironmentPreset();
297
- return {
298
- ...DEFAULT_CONFIG,
299
- ...BUILD_PRESETS[preset]
300
- };
301
- }
302
-
303
- /**
304
- * CLI log level to internal verbosity mapping
305
- * @since 5.0.0
306
- */
307
- export const CLI_LEVEL_MAP: Record<CLILogLevel, { verbosity: Verbosity; showPrimitives: boolean }> = {
308
- silent: { verbosity: 'silent', showPrimitives: false },
309
- quiet: { verbosity: 'error', showPrimitives: false },
310
- normal: { verbosity: 'info', showPrimitives: true },
311
- verbose: { verbosity: 'debug', showPrimitives: true },
312
- debug: { verbosity: 'debug', showPrimitives: true },
313
- } as const;
package/src/core.ts DELETED
@@ -1,397 +0,0 @@
1
- /**
2
- * @fileoverview Core Logger Module - Minimal logging without advanced features
3
- * @version 0.0.1
4
- *
5
- * This module provides the essential logging functionality without visual enhancements,
6
- * SVG support, or advanced styling. Perfect for lightweight applications or server-side usage.
7
- */
8
-
9
- // Core types
10
- import type {
11
- LogLevel,
12
- Verbosity,
13
- LoggerConfig,
14
- ILogHandler,
15
- LogMetadata,
16
- TimerEntry
17
- } from './types/index.js';
18
-
19
- // Core utilities
20
- import {
21
- parseStackTrace,
22
- formatTimestamp
23
- } from './utils/index.js';
24
-
25
- // Universal formatting and environment detection
26
- import {
27
- createPlainOutput,
28
- createOutput,
29
- getConsoleMethod,
30
- createLogEntry,
31
- formatTablePlain,
32
- safeSerialize,
33
- detectOptimalFormat,
34
- type OutputFormat
35
- } from './utils/formatting.js';
36
-
37
- import {
38
- isBrowser,
39
- isNode,
40
- getRuntimeEnvironment,
41
- supportsColors,
42
- supportsCSSColors
43
- } from './utils/environment.js';
44
-
45
- import { createStyledOutput } from './utils/output.js';
46
-
47
- // Constants
48
- import { DEFAULT_CONFIG, LEVEL_STYLES } from './constants.js';
49
-
50
- /**
51
- * Minimal Logger class with core functionality only
52
- *
53
- * @example
54
- * ```typescript
55
- * import { CoreLogger } from '@mks2508/better-logger/core';
56
- *
57
- * const logger = new CoreLogger();
58
- * logger.info('Hello world');
59
- * logger.error('Something went wrong', error);
60
- * ```
61
- */
62
- export class CoreLogger {
63
- private config: LoggerConfig;
64
- private scopedPrefix?: string;
65
- private handlers: ILogHandler[] = [];
66
- private timers: Map<string, TimerEntry> = new Map();
67
- private groupDepth: number = 0;
68
-
69
- /**
70
- * Creates a new CoreLogger instance
71
- * @param config - Optional configuration
72
- */
73
- constructor(config: Partial<LoggerConfig> = {}) {
74
- this.config = {
75
- ...DEFAULT_CONFIG,
76
- ...config,
77
- // Auto-configure based on environment
78
- enableColors: config.enableColors ?? (isBrowser ? true : false),
79
- enableTimestamps: config.enableTimestamps ?? true,
80
- enableStackTrace: config.enableStackTrace ?? false,
81
- autoDetectTheme: config.autoDetectTheme ?? true,
82
- outputFormat: config.outputFormat ?? 'auto'
83
- };
84
- }
85
-
86
- // ===== CONFIGURATION METHODS =====
87
-
88
- /**
89
- * Get current configuration
90
- */
91
- getConfig(): LoggerConfig {
92
- return { ...this.config };
93
- }
94
-
95
- /**
96
- * Sets the global prefix for all log messages
97
- */
98
- setGlobalPrefix(prefix: string): void {
99
- this.config.globalPrefix = prefix;
100
- }
101
-
102
- /**
103
- * Sets the verbosity level for filtering log output
104
- */
105
- setVerbosity(level: Verbosity): void {
106
- this.config.verbosity = level;
107
- }
108
-
109
- /**
110
- * Creates a scoped logger with a specific prefix
111
- */
112
- scope(prefix: string): CoreLogger {
113
- const scopedLogger = new CoreLogger(this.config);
114
- scopedLogger.scopedPrefix = prefix;
115
- scopedLogger.handlers = [...this.handlers];
116
- return scopedLogger;
117
- }
118
-
119
- /**
120
- * Adds a custom log handler for extensibility
121
- */
122
- addHandler(handler: ILogHandler): void {
123
- this.handlers.push(handler);
124
- }
125
-
126
- // ===== CORE LOGGING METHODS =====
127
-
128
- /**
129
- * Checks if a log level should be output based on current verbosity
130
- */
131
- private shouldLog(level: LogLevel): boolean {
132
- if (this.config.verbosity === 'silent') return false;
133
- const levels = { debug: 0, info: 1, warn: 2, error: 3, critical: 4 };
134
- return levels[level] >= levels[this.config.verbosity];
135
- }
136
-
137
- /**
138
- * Gets the effective prefix (global + scoped)
139
- */
140
- private getEffectivePrefix(): string | undefined {
141
- const parts = [this.config.globalPrefix, this.scopedPrefix].filter(Boolean);
142
- return parts.length > 0 ? parts.join(':') : undefined;
143
- }
144
-
145
- /**
146
- * Core logging method with universal formatting
147
- */
148
- private log(level: LogLevel, ...args: any[]): void {
149
- if (!this.shouldLog(level)) return;
150
-
151
- const prefix = this.getEffectivePrefix();
152
- const message = String(args[0] || '');
153
- const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
154
- const consoleMethod = getConsoleMethod(level);
155
-
156
- // Choose formatting based on environment and configuration
157
- if (isBrowser && this.config.enableColors && supportsCSSColors()) {
158
- // Browser with CSS styling
159
- try {
160
- const [format, ...styles] = createStyledOutput(
161
- level,
162
- LEVEL_STYLES,
163
- prefix,
164
- message,
165
- stackInfo,
166
- this.config.autoDetectTheme
167
- );
168
- console[consoleMethod](format, ...styles, ...args.slice(1));
169
- } catch (error) {
170
- // Fallback to universal formatting if CSS fails
171
- const output = createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
172
- console[consoleMethod](output, ...args.slice(1));
173
- }
174
- } else {
175
- // Node.js or browser without colors - use universal formatting
176
- const groupIndent = ' '.repeat(this.groupDepth);
177
- const output = groupIndent + createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
178
- console[consoleMethod](output, ...args.slice(1));
179
- }
180
-
181
- // Call custom handlers with structured metadata
182
- const logEntry = createLogEntry(level, message, args, prefix, stackInfo);
183
- const metadata: LogMetadata = {
184
- timestamp: logEntry.timestamp,
185
- level,
186
- prefix,
187
- stackInfo: logEntry.location,
188
- };
189
-
190
- this.handlers.forEach(handler => {
191
- try {
192
- handler.handle(level, message, args, metadata);
193
- } catch (error) {
194
- console.error('Log handler failed:', error);
195
- }
196
- });
197
- }
198
-
199
- /**
200
- * Logs debug information (lowest priority)
201
- */
202
- debug(...args: any[]): void {
203
- this.log('debug', ...args);
204
- }
205
-
206
- /**
207
- * Logs informational messages
208
- */
209
- info(...args: any[]): void {
210
- this.log('info', ...args);
211
- }
212
-
213
- /**
214
- * Logs warning messages
215
- */
216
- warn(...args: any[]): void {
217
- this.log('warn', ...args);
218
- }
219
-
220
- /**
221
- * Logs error messages
222
- */
223
- error(...args: any[]): void {
224
- this.log('error', ...args);
225
- }
226
-
227
- /**
228
- * Logs critical errors (highest priority)
229
- */
230
- critical(...args: any[]): void {
231
- this.log('critical', ...args);
232
- }
233
-
234
- /**
235
- * Logs trace information (detailed debugging)
236
- */
237
- trace(...args: any[]): void {
238
- this.log('debug', ...args);
239
- if (this.shouldLog('debug')) {
240
- console.trace(...args);
241
- }
242
- }
243
-
244
- // ===== BASIC ADVANCED FEATURES =====
245
-
246
- /**
247
- * Displays data in a table format
248
- */
249
- table(data: any, columns?: string[]): void {
250
- if (!this.shouldLog('info')) return;
251
-
252
- const prefix = this.getEffectivePrefix();
253
- const tableHeader = `[TABLE]${prefix ? ` [${prefix}]` : ''}:`;
254
-
255
- if (isBrowser && typeof console.table === 'function') {
256
- // Browser has native table support
257
- console.log(tableHeader);
258
- if (columns) {
259
- console.table(data, columns);
260
- } else {
261
- console.table(data);
262
- }
263
- } else {
264
- // Node.js or fallback - use plain text formatting
265
- console.log(tableHeader);
266
- const tableText = formatTablePlain(data, columns);
267
- console.log(tableText);
268
- }
269
- }
270
-
271
- /**
272
- * Starts a collapsible group in the console
273
- */
274
- group(label: string, collapsed: boolean = false): void {
275
- const prefix = this.getEffectivePrefix();
276
- const fullLabel = `${prefix ? `[${prefix}] ` : ''}${label}`;
277
-
278
- if (isBrowser && console.group && console.groupCollapsed) {
279
- // Browser supports native grouping
280
- if (collapsed) {
281
- console.groupCollapsed(fullLabel);
282
- } else {
283
- console.group(fullLabel);
284
- }
285
- } else {
286
- // Node.js fallback - just log the group label
287
- const groupStart = '┌─ ' + fullLabel;
288
- console.log(groupStart);
289
- }
290
-
291
- this.groupDepth++;
292
- }
293
-
294
- /**
295
- * Ends the current console group
296
- */
297
- groupEnd(): void {
298
- if (this.groupDepth > 0) {
299
- if (isBrowser && console.groupEnd) {
300
- console.groupEnd();
301
- } else {
302
- // Node.js fallback - log group end
303
- const groupEnd = '└─ (end group)';
304
- console.log(groupEnd);
305
- }
306
- this.groupDepth--;
307
- }
308
- }
309
-
310
- /**
311
- * Starts a timer with the given label
312
- */
313
- time(label: string): void {
314
- const startTime = this.getPerformanceNow();
315
- const timer: TimerEntry = {
316
- label,
317
- startTime,
318
- };
319
- this.timers.set(label, timer);
320
-
321
- const prefix = this.getEffectivePrefix();
322
- const message = `Timer started: ${label}`;
323
- const output = createPlainOutput('info', message, prefix);
324
- console.log(output);
325
- }
326
-
327
- /**
328
- * Ends a timer and logs the elapsed time
329
- */
330
- timeEnd(label: string): void {
331
- const timer = this.timers.get(label);
332
- if (!timer) {
333
- this.warn(`Timer '${label}' does not exist`);
334
- return;
335
- }
336
-
337
- const elapsed = this.getPerformanceNow() - timer.startTime;
338
- this.timers.delete(label);
339
-
340
- const prefix = this.getEffectivePrefix();
341
- const message = `Timer ended: ${label} - ${elapsed.toFixed(2)}ms`;
342
- const output = createPlainOutput('info', message, prefix);
343
- console.log(output);
344
- }
345
-
346
- /**
347
- * Gets performance.now() or fallback for older environments
348
- */
349
- private getPerformanceNow(): number {
350
- if (typeof performance !== 'undefined' && performance.now) {
351
- return performance.now();
352
- }
353
-
354
- if (isNode && process.hrtime) {
355
- // Node.js high-resolution time
356
- const [seconds, nanoseconds] = process.hrtime();
357
- return seconds * 1000 + nanoseconds / 1000000;
358
- }
359
-
360
- // Fallback to Date.now()
361
- return Date.now();
362
- }
363
- }
364
-
365
- // Create and export singleton instance for convenience
366
- const coreLogger = new CoreLogger();
367
-
368
- /**
369
- * Export individual methods for convenience (with proper binding)
370
- */
371
- export const debug = (...args: any[]) => coreLogger.debug(...args);
372
- export const info = (...args: any[]) => coreLogger.info(...args);
373
- export const warn = (...args: any[]) => coreLogger.warn(...args);
374
- export const error = (...args: any[]) => coreLogger.error(...args);
375
- export const critical = (...args: any[]) => coreLogger.critical(...args);
376
- export const trace = (...args: any[]) => coreLogger.trace(...args);
377
- export const table = (data: any, columns?: string[]) => coreLogger.table(data, columns);
378
- export const group = (label: string, collapsed?: boolean) => coreLogger.group(label, collapsed);
379
- export const groupEnd = () => coreLogger.groupEnd();
380
- export const time = (label: string) => coreLogger.time(label);
381
- export const timeEnd = (label: string) => coreLogger.timeEnd(label);
382
- export const setGlobalPrefix = (prefix: string) => coreLogger.setGlobalPrefix(prefix);
383
- export const scope = (prefix: string) => coreLogger.scope(prefix);
384
- export const setVerbosity = (level: Verbosity) => coreLogger.setVerbosity(level);
385
- export const addHandler = (handler: ILogHandler) => coreLogger.addHandler(handler);
386
-
387
- // Export the singleton as default
388
- export default coreLogger;
389
-
390
- // Re-export core types
391
- export type {
392
- LogLevel,
393
- Verbosity,
394
- LoggerConfig,
395
- ILogHandler,
396
- LogMetadata
397
- } from './types/index.js';