@mks2508/better-logger 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/CLAUDE.md +113 -0
  3. package/dist/assets/index-DxvJByYN.js +183 -0
  4. package/dist/index.html +334 -0
  5. package/dist/vite.svg +1 -0
  6. package/index.html +334 -0
  7. package/package.json +35 -0
  8. package/public/vite.svg +1 -0
  9. package/src/Logger.ts +577 -0
  10. package/src/Logger.ts.backup +1684 -0
  11. package/src/cli/CommandProcessor.ts +77 -0
  12. package/src/cli/commands/ConfigCommand.ts +93 -0
  13. package/src/cli/commands/ExportCommand.ts +271 -0
  14. package/src/cli/commands/StatusCommand.ts +111 -0
  15. package/src/cli/commands/ThemeCommand.ts +88 -0
  16. package/src/cli/help.ts +127 -0
  17. package/src/cli/index.ts +59 -0
  18. package/src/constants.ts +89 -0
  19. package/src/example.ts +88 -0
  20. package/src/handlers/AnalyticsLogHandler.ts +22 -0
  21. package/src/handlers/ExportLogHandler.ts +447 -0
  22. package/src/handlers/FileLogHandler.ts +30 -0
  23. package/src/handlers/RemoteLogHandler.ts +42 -0
  24. package/src/handlers/index.ts +8 -0
  25. package/src/index.ts +122 -0
  26. package/src/main.ts +126 -0
  27. package/src/style.css +96 -0
  28. package/src/styling/StyleBuilder.ts +305 -0
  29. package/src/styling/banners.ts +168 -0
  30. package/src/styling/index.ts +12 -0
  31. package/src/styling/themes.ts +235 -0
  32. package/src/types/core.ts +80 -0
  33. package/src/types/handlers.ts +95 -0
  34. package/src/types/index.ts +29 -0
  35. package/src/typescript.svg +1 -0
  36. package/src/utils/index.ts +18 -0
  37. package/src/utils/output.ts +127 -0
  38. package/src/utils/stackTrace.ts +66 -0
  39. package/src/utils/timestamps.ts +80 -0
  40. package/src/vite-env.d.ts +1 -0
  41. package/tsconfig.json +24 -0
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @fileoverview Help system for Advanced Logger CLI
3
+ */
4
+
5
+ import type { ICommand } from './CommandProcessor.js';
6
+ import type { Logger } from '../Logger.js';
7
+ import { StyleBuilder } from '../styling/index.js';
8
+
9
+ /**
10
+ * Help command - show comprehensive CLI help
11
+ */
12
+ export class HelpCommand implements ICommand {
13
+ name = 'help';
14
+ description = 'Show CLI help and available commands';
15
+ usage = '/help [command]';
16
+
17
+ execute(_args: string, logger: Logger): void {
18
+ const helpStyle = new StyleBuilder()
19
+ .bg('linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%)')
20
+ .color('#495057')
21
+ .padding('15px 20px')
22
+ .rounded('8px')
23
+ .border('1px solid #dee2e6')
24
+ .font('Monaco, Consolas, monospace')
25
+ .size('13px')
26
+ .build();
27
+
28
+ const helpText = `
29
+ ╭─────────────── ADVANCED LOGGER CLI COMMANDS ─────────────────╮
30
+ │ │
31
+ │ CONFIGURATION │
32
+ │ /config Show current configuration │
33
+ │ /config {json} Apply JSON configuration │
34
+ │ /config key=val Apply key-value configuration │
35
+ │ /themes Show available themes │
36
+ │ /banners Show available banner types │
37
+ │ /banner [type] Change/show banner type │
38
+ │ /status Show logger status & buffer stats │
39
+ │ /demo Show feature demonstration │
40
+ │ /reset Reset to default configuration │
41
+ │ │
42
+ │ EXPORT & CLIPBOARD │
43
+ │ /export <format> Export logs (json|csv|md|plain|html) │
44
+ │ /copy <format> Copy logs to clipboard │
45
+ │ /buffer-size N Set log buffer size │
46
+ │ /buffer-info Show buffer statistics │
47
+ │ /clear-buffer Clear stored logs │
48
+ │ │
49
+ │ EXPORT FILTERS (for export/copy commands) │
50
+ │ --level error,warn Filter by log levels │
51
+ │ --since 2h Logs from last 2 hours │
52
+ │ --until 1h Logs until 1 hour ago │
53
+ │ --prefix API,DB Filter by prefixes │
54
+ │ --exclude-prefix INT Exclude prefixes │
55
+ │ --last 50 Last 50 logs only │
56
+ │ --first 25 First 25 logs only │
57
+ │ --search "error" Search in log messages │
58
+ │ --with-stack Only logs with stack traces │
59
+ │ --errors-only Only error + critical logs │
60
+ │ --group-by level Group by level/prefix/hour │
61
+ │ │
62
+ │ EXPORT OPTIONS │
63
+ │ --minimal Minimal output format │
64
+ │ --compact Remove extra whitespace │
65
+ │ --styled Include styling (HTML format) │
66
+ │ │
67
+ ├──────────────────── CONFIGURATION OPTIONS ─────────────────┤
68
+ │ │
69
+ │ theme: default | dark | light | neon | minimal | cyberpunk│
70
+ │ bannerType: simple | ascii | unicode | svg | animated │
71
+ │ verbosity: debug | info | warn | error | critical | silent│
72
+ │ enableColors: true | false │
73
+ │ enableTimestamps: true | false │
74
+ │ enableStackTrace: true | false │
75
+ │ globalPrefix: "string" │
76
+ │ bufferSize: number (50-10000) │
77
+ │ │
78
+ ├──────────────────────── EXAMPLES ──────────────────────────┤
79
+ │ │
80
+ │ Basic Configuration: │
81
+ │ /config {"theme":"dark","verbosity":"debug"} │
82
+ │ /config theme=neon,bufferSize=2000 │
83
+ │ /banner animated Change to animated banner │
84
+ │ │
85
+ │ Export Examples: │
86
+ │ /export json --level=error,warn --last=25 │
87
+ │ /export csv --since=2h --prefix=API │
88
+ │ /export markdown --group-by=level --errors-only │
89
+ │ /export html --styled --since=1h │
90
+ │ │
91
+ │ Clipboard Examples: │
92
+ │ /copy plain --minimal --last=10 │
93
+ │ /copy json --search="authentication" --compact │
94
+ │ /copy csv --since=30m --exclude-prefix=DEBUG │
95
+ │ │
96
+ │ Buffer Management: │
97
+ │ /buffer-size 5000 Increase buffer to 5000 logs │
98
+ │ /buffer-info Show detailed buffer statistics │
99
+ │ /clear-buffer Clear all stored logs │
100
+ │ │
101
+ │ Time Formats: │
102
+ │ --since=2h 2 hours ago │
103
+ │ --since=30m 30 minutes ago │
104
+ │ --since=1d 1 day ago │
105
+ │ --since="2024-01-01T10:00:00Z" Specific ISO date │
106
+ │ │
107
+ ╰─────────────────────────────────────────────────────────────╯`;
108
+
109
+ console.log(`%c${helpText}`, helpStyle);
110
+
111
+ // Show quick tips
112
+ logger.group('💡 Quick Tips');
113
+ const tips = [
114
+ 'Use /demo to see all logger features in action',
115
+ 'Logs are automatically stored in a circular buffer for export',
116
+ 'Export formats: JSON (structured), CSV (Excel), Markdown (readable), Plain (simple), HTML (styled)',
117
+ 'Time filters support relative (2h, 30m) and absolute (ISO) formats',
118
+ 'Combine multiple filters: /export json --level=error --since=1h --search="auth"',
119
+ 'Use /copy for quick clipboard access instead of /export'
120
+ ];
121
+
122
+ tips.forEach(tip => {
123
+ logger.info(`• ${tip}`);
124
+ });
125
+ logger.groupEnd();
126
+ }
127
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @fileoverview CLI system exports for Advanced Logger
3
+ */
4
+
5
+ // Core CLI system
6
+ export { CommandProcessor, type ICommand } from './CommandProcessor.js';
7
+ import { CommandProcessor } from './CommandProcessor.js';
8
+
9
+ // Commands
10
+ export { ConfigCommand } from './commands/ConfigCommand.js';
11
+ export { ThemesCommand, BannersCommand, BannerCommand } from './commands/ThemeCommand.js';
12
+ export { StatusCommand, ResetCommand, DemoCommand } from './commands/StatusCommand.js';
13
+ export {
14
+ ExportCommand,
15
+ CopyCommand,
16
+ BufferSizeCommand,
17
+ ClearBufferCommand,
18
+ BufferInfoCommand
19
+ } from './commands/ExportCommand.js';
20
+
21
+ // Help system
22
+ export { HelpCommand } from './help.js';
23
+
24
+ // Import all commands
25
+ import { HelpCommand } from './help.js';
26
+ import { ConfigCommand } from './commands/ConfigCommand.js';
27
+ import { ThemesCommand, BannersCommand, BannerCommand } from './commands/ThemeCommand.js';
28
+ import { StatusCommand, ResetCommand, DemoCommand } from './commands/StatusCommand.js';
29
+ import {
30
+ ExportCommand,
31
+ CopyCommand,
32
+ BufferSizeCommand,
33
+ ClearBufferCommand,
34
+ BufferInfoCommand
35
+ } from './commands/ExportCommand.js';
36
+
37
+ /**
38
+ * Create and configure default CLI processor
39
+ */
40
+ export function createDefaultCLI(): CommandProcessor {
41
+ const processor = new CommandProcessor();
42
+
43
+ // Register all default commands
44
+ processor.registerCommand(new HelpCommand());
45
+ processor.registerCommand(new ConfigCommand());
46
+ processor.registerCommand(new ThemesCommand());
47
+ processor.registerCommand(new BannersCommand());
48
+ processor.registerCommand(new BannerCommand());
49
+ processor.registerCommand(new StatusCommand());
50
+ processor.registerCommand(new ResetCommand());
51
+ processor.registerCommand(new DemoCommand());
52
+ processor.registerCommand(new ExportCommand());
53
+ processor.registerCommand(new CopyCommand());
54
+ processor.registerCommand(new BufferSizeCommand());
55
+ processor.registerCommand(new ClearBufferCommand());
56
+ processor.registerCommand(new BufferInfoCommand());
57
+
58
+ return processor;
59
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @fileoverview Global constants for Advanced Logger
3
+ */
4
+
5
+ import type { LogLevel } from './types/index.js';
6
+
7
+ /**
8
+ * Default configuration values
9
+ */
10
+ export const DEFAULT_CONFIG = {
11
+ verbosity: 'info' as const,
12
+ enableColors: true,
13
+ enableTimestamps: true,
14
+ enableStackTrace: true,
15
+ theme: 'default' as const,
16
+ bannerType: 'simple' as const,
17
+ bufferSize: 1000,
18
+ } as const;
19
+
20
+ /**
21
+ * Maximum allowed buffer sizes for performance
22
+ */
23
+ export const BUFFER_LIMITS = {
24
+ MIN_SIZE: 50,
25
+ DEFAULT_SIZE: 1000,
26
+ MAX_SIZE: 10000,
27
+ } as const;
28
+
29
+ /**
30
+ * Export format definitions with extensions
31
+ */
32
+ export const EXPORT_FORMATS = {
33
+ json: { extension: '.json', mimeType: 'application/json' },
34
+ csv: { extension: '.csv', mimeType: 'text/csv' },
35
+ markdown: { extension: '.md', mimeType: 'text/markdown' },
36
+ plain: { extension: '.txt', mimeType: 'text/plain' },
37
+ html: { extension: '.html', mimeType: 'text/html' },
38
+ } as const;
39
+
40
+ /**
41
+ * CLI command definitions
42
+ */
43
+ export const CLI_COMMANDS = {
44
+ config: 'config',
45
+ help: 'help',
46
+ themes: 'themes',
47
+ banners: 'banners',
48
+ banner: 'banner',
49
+ status: 'status',
50
+ reset: 'reset',
51
+ demo: 'demo',
52
+ export: 'export',
53
+ copy: 'copy',
54
+ 'buffer-size': 'buffer-size',
55
+ 'clear-buffer': 'clear-buffer',
56
+ 'buffer-info': 'buffer-info',
57
+ } as const;
58
+
59
+ /**
60
+ * Time parsing constants for relative time filters
61
+ */
62
+ export const TIME_UNITS = {
63
+ ms: 1,
64
+ s: 1000,
65
+ m: 60 * 1000,
66
+ h: 60 * 60 * 1000,
67
+ d: 24 * 60 * 60 * 1000,
68
+ } as const;
69
+
70
+ /**
71
+ * Default styling values
72
+ */
73
+ export const STYLE_DEFAULTS = {
74
+ FONT_FAMILY: 'Monaco, Consolas, monospace',
75
+ FONT_SIZE: '12px',
76
+ BORDER_RADIUS: '4px',
77
+ PADDING: '4px 8px',
78
+ } as const;
79
+
80
+ /**
81
+ * Level priority mapping for filtering
82
+ */
83
+ export const LEVEL_PRIORITIES: Record<LogLevel, number> = {
84
+ debug: 0,
85
+ info: 1,
86
+ warn: 2,
87
+ error: 3,
88
+ critical: 4,
89
+ } as const;
package/src/example.ts ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @fileoverview Example usage of the advanced Logger system
3
+ */
4
+
5
+ import Logger, {
6
+ debug,
7
+ info,
8
+ warn,
9
+ error,
10
+ success,
11
+ createScopedLogger,
12
+ setGlobalPrefix,
13
+ setVerbosity,
14
+ FileLogHandler,
15
+ AnalyticsLogHandler
16
+ } from './Logger.js';
17
+ import { StyleBuilder } from './styling/index.js';
18
+
19
+ // Example usage demonstration
20
+ function demonstrateLogger() {
21
+ // Set up global configuration
22
+ setGlobalPrefix('APP');
23
+ setVerbosity('debug');
24
+
25
+ // Add custom handlers
26
+ Logger.addHandler(new FileLogHandler('app.log'));
27
+ Logger.addHandler(new AnalyticsLogHandler());
28
+
29
+ // Create scoped loggers
30
+ const apiLogger = createScopedLogger('API');
31
+ const dbLogger = createScopedLogger('DATABASE');
32
+
33
+ // Basic logging
34
+ info('🚀 Application started successfully');
35
+ debug('Debug information', { config: { mode: 'development' } });
36
+ warn('⚠️ This is a warning message');
37
+ error('❌ An error occurred', new Error('Sample error'));
38
+ success('✅ User authentication successful');
39
+
40
+ // Scoped logging
41
+ apiLogger.info('Fetching user data', { endpoint: '/api/users' });
42
+ dbLogger.debug('Database query executed', { query: 'SELECT * FROM users' });
43
+
44
+ // Advanced features
45
+ Logger.group('User Session Details');
46
+ apiLogger.table([
47
+ { id: 1, name: 'John Doe', email: 'john@example.com' },
48
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com' }
49
+ ]);
50
+ Logger.groupEnd();
51
+
52
+ // Performance timing
53
+ Logger.time('data-processing');
54
+ // Simulate some processing
55
+ setTimeout(() => {
56
+ Logger.timeEnd('data-processing');
57
+ }, 100);
58
+
59
+ // Critical error with stack trace
60
+ Logger.critical('🔥 Critical system failure detected');
61
+
62
+ // Custom styled logging
63
+ console.log(
64
+ '%cCustom Styled Message',
65
+ new StyleBuilder()
66
+ .bg('linear-gradient(45deg, #ff6b6b, #feca57)')
67
+ .color('#ffffff')
68
+ .padding('10px 15px')
69
+ .rounded('8px')
70
+ .shadow('0 4px 8px rgba(0,0,0,0.2)')
71
+ .bold()
72
+ .build()
73
+ );
74
+
75
+ // Grouped logging with data
76
+ const users = [
77
+ { name: 'Alice', role: 'admin' },
78
+ { name: 'Bob', role: 'user' },
79
+ { name: 'Charlie', role: 'admin' }
80
+ ];
81
+
82
+ Logger.logGrouped(users, (user) => user.role);
83
+ }
84
+
85
+ // Run the demonstration
86
+ demonstrateLogger();
87
+
88
+ export { demonstrateLogger };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Analytics log handler for Advanced Logger
3
+ */
4
+
5
+ import type { ILogHandler, LogLevel, LogMetadata } from '../types/index.js';
6
+
7
+ /**
8
+ * Example custom handler for analytics demonstration
9
+ */
10
+ export class AnalyticsLogHandler implements ILogHandler {
11
+ handle(level: LogLevel, message: string, _args: any[], metadata: LogMetadata): void {
12
+ // In a real implementation, this could send analytics data
13
+ if (level === 'error' || level === 'critical') {
14
+ // Track errors for analytics
15
+ console.debug('Analytics: Error tracked', {
16
+ level,
17
+ message,
18
+ timestamp: metadata.timestamp
19
+ });
20
+ }
21
+ }
22
+ }