@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.
- package/.claude/settings.local.json +13 -0
- package/CLAUDE.md +113 -0
- package/dist/assets/index-DxvJByYN.js +183 -0
- package/dist/index.html +334 -0
- package/dist/vite.svg +1 -0
- package/index.html +334 -0
- package/package.json +35 -0
- package/public/vite.svg +1 -0
- package/src/Logger.ts +577 -0
- package/src/Logger.ts.backup +1684 -0
- package/src/cli/CommandProcessor.ts +77 -0
- package/src/cli/commands/ConfigCommand.ts +93 -0
- package/src/cli/commands/ExportCommand.ts +271 -0
- package/src/cli/commands/StatusCommand.ts +111 -0
- package/src/cli/commands/ThemeCommand.ts +88 -0
- package/src/cli/help.ts +127 -0
- package/src/cli/index.ts +59 -0
- package/src/constants.ts +89 -0
- package/src/example.ts +88 -0
- package/src/handlers/AnalyticsLogHandler.ts +22 -0
- package/src/handlers/ExportLogHandler.ts +447 -0
- package/src/handlers/FileLogHandler.ts +30 -0
- package/src/handlers/RemoteLogHandler.ts +42 -0
- package/src/handlers/index.ts +8 -0
- package/src/index.ts +122 -0
- package/src/main.ts +126 -0
- package/src/style.css +96 -0
- package/src/styling/StyleBuilder.ts +305 -0
- package/src/styling/banners.ts +168 -0
- package/src/styling/index.ts +12 -0
- package/src/styling/themes.ts +235 -0
- package/src/types/core.ts +80 -0
- package/src/types/handlers.ts +95 -0
- package/src/types/index.ts +29 -0
- package/src/typescript.svg +1 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/output.ts +127 -0
- package/src/utils/stackTrace.ts +66 -0
- package/src/utils/timestamps.ts +80 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +24 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is an **Advanced Logger** TypeScript library that provides state-of-the-art console logging with advanced CSS styling, performance monitoring, and extensible architecture. The project is built with modern TypeScript patterns and targets browser environments.
|
|
8
|
+
|
|
9
|
+
### Core Architecture
|
|
10
|
+
|
|
11
|
+
- **Main Logger Class**: `src/Logger.ts` contains the primary Logger class with advanced styling capabilities
|
|
12
|
+
- **Style System**: Built around a fluent `StyleBuilder` class that creates CSS-in-JS console styles
|
|
13
|
+
- **Handler Architecture**: Extensible system with `ILogHandler` interface for custom log destinations (File, Remote, Analytics)
|
|
14
|
+
- **Scoped Logging**: Support for prefixed logger instances for different modules/components
|
|
15
|
+
- **Performance Monitoring**: Built-in timing capabilities with `time()` and `timeEnd()`
|
|
16
|
+
|
|
17
|
+
### Key Components
|
|
18
|
+
|
|
19
|
+
- **Logger Core** (`src/Logger.ts:373-732`): Main logger implementation with hierarchical log levels
|
|
20
|
+
- **Style Builder** (`src/Logger.ts:141-226`): Chainable CSS styling system
|
|
21
|
+
- **Log Handlers** (`src/Logger.ts:737-971`): FileLogHandler, RemoteLogHandler, AnalyticsLogHandler
|
|
22
|
+
- **Demo/Test Interface** (`index.html`): Interactive test page with styled buttons
|
|
23
|
+
- **Usage Examples** (`src/example.ts`, `src/main.ts`): Comprehensive usage demonstrations
|
|
24
|
+
|
|
25
|
+
## Development Commands
|
|
26
|
+
|
|
27
|
+
### Build & Development
|
|
28
|
+
```bash
|
|
29
|
+
npm run dev # Start Vite dev server (runs on http://localhost:5173)
|
|
30
|
+
npm run build # TypeScript compilation + Vite production build
|
|
31
|
+
npm run preview # Preview production build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Testing the Logger
|
|
35
|
+
- Open `index.html` in development server
|
|
36
|
+
- Use browser DevTools console to see styled output
|
|
37
|
+
- Click buttons to test different log levels and features
|
|
38
|
+
|
|
39
|
+
## Architecture Patterns
|
|
40
|
+
|
|
41
|
+
### Log Level Hierarchy
|
|
42
|
+
```typescript
|
|
43
|
+
LOG_LEVELS = {
|
|
44
|
+
debug: 0, // Lowest priority
|
|
45
|
+
info: 1,
|
|
46
|
+
warn: 2,
|
|
47
|
+
error: 3,
|
|
48
|
+
critical: 4 // Highest priority
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Styling System
|
|
53
|
+
The project uses a sophisticated CSS-in-JS approach:
|
|
54
|
+
- **StyleBuilder**: Chainable pattern for building console CSS styles
|
|
55
|
+
- **LEVEL_STYLES**: Pre-configured gradients, colors, and shadows for each log level
|
|
56
|
+
- **Dynamic Styling**: Uses `%c` console formatting with built CSS strings
|
|
57
|
+
|
|
58
|
+
### Handler Pattern
|
|
59
|
+
Extensible logging through the `ILogHandler` interface:
|
|
60
|
+
- Handlers receive log metadata including timestamps, stack traces, and prefixes
|
|
61
|
+
- Multiple handlers can be registered simultaneously
|
|
62
|
+
- Built-in handlers for file logging, remote logging, and analytics
|
|
63
|
+
|
|
64
|
+
### Performance Features
|
|
65
|
+
- **Stack Trace Parsing**: Automatic caller location detection
|
|
66
|
+
- **Performance Timers**: Built-in timing with `performance.now()`
|
|
67
|
+
- **Grouping**: Console grouping with automatic indentation
|
|
68
|
+
- **Table Display**: Formatted data tables in console
|
|
69
|
+
|
|
70
|
+
## Code Conventions
|
|
71
|
+
|
|
72
|
+
### TypeScript Patterns
|
|
73
|
+
- Uses modern ES2022+ features with strict typing
|
|
74
|
+
- Leverages `as const` for readonly object typing
|
|
75
|
+
- Interface-based extensibility patterns
|
|
76
|
+
- Generic types for flexible APIs (`logGrouped<T>`)
|
|
77
|
+
|
|
78
|
+
### Styling Conventions
|
|
79
|
+
- All styles use CSS gradients and modern properties
|
|
80
|
+
- Consistent color palette across log levels
|
|
81
|
+
- Responsive design patterns in HTML interface
|
|
82
|
+
- CSS Grid for layout with modern browser features
|
|
83
|
+
|
|
84
|
+
### Error Handling
|
|
85
|
+
- Graceful degradation when browser features unavailable
|
|
86
|
+
- Try-catch blocks around experimental features
|
|
87
|
+
- Silent failure for log handlers to prevent infinite loops
|
|
88
|
+
|
|
89
|
+
## Browser Compatibility
|
|
90
|
+
|
|
91
|
+
### Modern Features Used
|
|
92
|
+
- **CSS Gradients**: Extensive use of `linear-gradient()`
|
|
93
|
+
- **Performance API**: `performance.now()` for timing
|
|
94
|
+
- **Modern Console**: `%c` formatting, `console.table()`, `console.group()`
|
|
95
|
+
- **ES2022 Features**: Object.groupBy (with fallback)
|
|
96
|
+
- **Fetch API**: Used in RemoteLogHandler
|
|
97
|
+
|
|
98
|
+
### Fallback Patterns
|
|
99
|
+
- Stack trace parsing handles different browser formats (Chrome/Firefox)
|
|
100
|
+
- Object.groupBy fallback to reduce()
|
|
101
|
+
- Modern Date API with ISO formatting fallback
|
|
102
|
+
|
|
103
|
+
## Key Files Structure
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
src/
|
|
107
|
+
โโโ Logger.ts # Main logger implementation (972 lines)
|
|
108
|
+
โโโ example.ts # Comprehensive usage examples
|
|
109
|
+
โโโ main.ts # Test functions for HTML interface
|
|
110
|
+
โโโ style.css # Basic Vite styling (not logger-related)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The logger is designed as a single-file library with comprehensive TypeScript documentation and can be imported as individual functions or as a class instance.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const i of n.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function t(o){const n={};return o.integrity&&(n.integrity=o.integrity),o.referrerPolicy&&(n.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?n.credentials="include":o.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function r(o){if(o.ep)return;o.ep=!0;const n=t(o);fetch(o.href,n)}})();function k(){try{const s=new Error().stack;if(!s)return null;const e=s.split(`
|
|
2
|
+
`).filter(t=>t.trim());for(let t=1;t<e.length;t++){const r=e[t];if(r.includes("parseStackTrace")||r.includes("Logger.")||r.includes(".log(")||r.includes("createStyledOutput"))continue;let o;const n=r.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);if(n)o=n;else{const i=r.match(/(.+?)@(.+?):(\d+):(\d+)$/);if(i)o=i;else{const a=r.match(/(\S+)?@(.+?):(\d+):(\d+)$/);a&&(o=a)}}if(o){const[,i,a,l,c]=o;return{file:a?.split("/").pop()?.split("?")[0]||"unknown",line:parseInt(l,10)||0,column:parseInt(c,10)||0,function:i?.trim()||void 0}}}return null}catch{return null}}const T={verbosity:"info",enableColors:!0,enableTimestamps:!0,enableStackTrace:!0,theme:"default",bannerType:"simple",bufferSize:1e3},x={MIN_SIZE:50,DEFAULT_SIZE:1e3,MAX_SIZE:1e4},E={json:{extension:".json",mimeType:"application/json"},csv:{extension:".csv",mimeType:"text/csv"},markdown:{extension:".md",mimeType:"text/markdown"},plain:{extension:".txt",mimeType:"text/plain"},html:{extension:".html",mimeType:"text/html"}},O={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};function _(){try{return new Date().toISOString()}catch{return new Date().toISOString()}}function Y(s){const e=s.match(/^(\d+)(ms|s|m|h|d)$/);if(!e)throw new Error(`Invalid time format: ${s}. Use format like "2h", "30m", "1d"`);const[,t,r]=e,o=O[r];return parseInt(t,10)*o}function L(s){if(s instanceof Date)return s;if(typeof s=="number")return new Date(Date.now()-s*O.h);if(typeof s=="string"){const e=new Date(s);if(!isNaN(e.getTime()))return e;try{const t=Y(s);return new Date(Date.now()-t)}catch{throw new Error(`Invalid time format: ${s}`)}}throw new Error(`Unsupported time input type: ${typeof s}`)}function b(s,e="short"){switch(e){case"time-only":return s.toTimeString().slice(0,8);case"full":return s.toISOString();case"short":default:return s.toISOString().slice(11,23)}}class d{styles=[];constructor(e=""){e&&this.styles.push(e)}bg(e){return this.styles.push(`background: ${e}`),this}color(e){return this.styles.push(`color: ${e}`),this}border(e){return this.styles.push(`border: ${e}`),this}shadow(e){return this.styles.push(`box-shadow: ${e}`),this}padding(e){return this.styles.push(`padding: ${e}`),this}margin(e){return this.styles.push(`margin: ${e}`),this}rounded(e="4px"){return this.styles.push(`border-radius: ${e}`),this}bold(){return this.styles.push("font-weight: bold"),this}font(e){return this.styles.push(`font-family: ${e}`),this}size(e){return this.styles.push(`font-size: ${e}`),this}lineHeight(e){return this.styles.push(`line-height: ${e}`),this}underline(){return this.styles.push("text-decoration: underline"),this}uppercase(){return this.styles.push("text-transform: uppercase"),this}opacity(e){return this.styles.push(`opacity: ${e}`),this}display(e){return this.styles.push(`display: ${e}`),this}position(e){return this.styles.push(`position: ${e}`),this}transform(e){return this.styles.push(`transform: ${e}`),this}animation(e){return this.styles.push(`animation: ${e}`),this}transition(e){return this.styles.push(`transition: ${e}`),this}cursor(e){return this.styles.push(`cursor: ${e}`),this}custom(e,t){return this.styles.push(`${e}: ${t}`),this}css(e,t){return this.custom(e,t)}build(){return this.styles.join("; ")}clear(){return this.styles=[],this}clone(){const e=new d;return e.styles=[...this.styles],e}merge(e){return this.styles.push(...e.styles),this}}function Q(){const s=new d;return new Proxy(s,{get(e,t){if(t in e){const r=e[t];return typeof r=="function"?r.bind(e):r}}})}Q();const S={success:()=>new d().bg("linear-gradient(135deg, #00b894 0%, #00a085 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),error:()=>new d().bg("linear-gradient(135deg, #e84393 0%, #d63031 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),warning:()=>new d().bg("linear-gradient(135deg, #fdcb6e 0%, #e17055 100%)").color("#2d3436").padding("4px 8px").rounded("4px").bold(),info:()=>new d().bg("linear-gradient(135deg, #74b9ff 0%, #0984e3 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),debug:()=>new d().bg("linear-gradient(135deg, #667eea 0%, #764ba2 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),muted:()=>new d().color("#6c757d").font("Monaco, Consolas, monospace").size("12px"),accent:()=>new d().bg("#f8f9fa").color("#495057").padding("2px 6px").rounded("3px").border("1px solid #dee2e6"),neon:()=>new d().bg("linear-gradient(135deg, #0f3460 0%, #e94560 100%)").color("#00ffff").padding("4px 8px").rounded("4px").bold().shadow("0 0 10px rgba(0, 255, 255, 0.5)")},h={default:{debug:{emoji:"๐",label:"DEBUG",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",color:"#ffffff",border:"1px solid #667eea",shadow:"0 2px 4px rgba(102, 126, 234, 0.3)"},info:{emoji:"โน๏ธ",label:"INFO",background:"linear-gradient(135deg, #74b9ff 0%, #0984e3 100%)",color:"#ffffff",border:"1px solid #74b9ff",shadow:"0 2px 4px rgba(116, 185, 255, 0.3)"},warn:{emoji:"โ ๏ธ",label:"WARN",background:"linear-gradient(135deg, #fdcb6e 0%, #e17055 100%)",color:"#2d3436",border:"1px solid #fdcb6e",shadow:"0 2px 4px rgba(253, 203, 110, 0.3)"},error:{emoji:"โ",label:"ERROR",background:"linear-gradient(135deg, #e84393 0%, #d63031 100%)",color:"#ffffff",border:"1px solid #e84393",shadow:"0 2px 4px rgba(232, 67, 147, 0.3)"},success:{emoji:"โ
",label:"SUCCESS",background:"linear-gradient(135deg, #00b894 0%, #00a085 100%)",color:"#ffffff",border:"1px solid #00b894",shadow:"0 2px 4px rgba(0, 184, 148, 0.3)"},critical:{emoji:"๐ฅ",label:"CRITICAL",background:"linear-gradient(135deg, #ff3838 0%, #ff1744 100%)",color:"#ffffff",border:"2px solid #ff3838",shadow:"0 4px 8px rgba(255, 56, 56, 0.5)"}},dark:{debug:{emoji:"๐",label:"DEBUG",background:"linear-gradient(135deg, #2d3748 0%, #4a5568 100%)",color:"#e2e8f0",border:"1px solid #4a5568",shadow:"0 2px 4px rgba(45, 55, 72, 0.8)"},info:{emoji:"๐ก",label:"INFO",background:"linear-gradient(135deg, #1a202c 0%, #2d3748 100%)",color:"#90cdf4",border:"1px solid #3182ce",shadow:"0 2px 4px rgba(26, 32, 44, 0.8)"},warn:{emoji:"โก",label:"WARN",background:"linear-gradient(135deg, #744210 0%, #975a16 100%)",color:"#faf089",border:"1px solid #d69e2e",shadow:"0 2px 4px rgba(116, 66, 16, 0.8)"},error:{emoji:"๐",label:"ERROR",background:"linear-gradient(135deg, #742a2a 0%, #9b2c2c 100%)",color:"#feb2b2",border:"1px solid #e53e3e",shadow:"0 2px 4px rgba(116, 42, 42, 0.8)"},success:{emoji:"๐ฏ",label:"SUCCESS",background:"linear-gradient(135deg, #276749 0%, #2f855a 100%)",color:"#9ae6b4",border:"1px solid #38a169",shadow:"0 2px 4px rgba(39, 103, 73, 0.8)"},critical:{emoji:"๐ฅ",label:"CRITICAL",background:"linear-gradient(135deg, #1a1a1a 0%, #ff0000 100%)",color:"#ffffff",border:"2px solid #ff0000",shadow:"0 4px 8px rgba(255, 0, 0, 0.9)"}},neon:{debug:{emoji:"โก",label:"DEBUG",background:"linear-gradient(135deg, #0f3460 0%, #e94560 100%)",color:"#00ffff",border:"1px solid #00ffff",shadow:"0 0 10px rgba(0, 255, 255, 0.5)"},info:{emoji:"๐ฎ",label:"INFO",background:"linear-gradient(135deg, #16213e 0%, #0f3460 100%)",color:"#00ff41",border:"1px solid #00ff41",shadow:"0 0 10px rgba(0, 255, 65, 0.5)"},warn:{emoji:"โ ๏ธ",label:"WARN",background:"linear-gradient(135deg, #533a03 0%, #e94560 100%)",color:"#ffff00",border:"1px solid #ffff00",shadow:"0 0 10px rgba(255, 255, 0, 0.5)"},error:{emoji:"๐ฅ",label:"ERROR",background:"linear-gradient(135deg, #5c0a0a 0%, #ff073a 100%)",color:"#ff073a",border:"1px solid #ff073a",shadow:"0 0 10px rgba(255, 7, 58, 0.8)"},success:{emoji:"โจ",label:"SUCCESS",background:"linear-gradient(135deg, #0a5c0a 0%, #39ff14 100%)",color:"#39ff14",border:"1px solid #39ff14",shadow:"0 0 10px rgba(57, 255, 20, 0.8)"},critical:{emoji:"๐",label:"CRITICAL",background:"linear-gradient(135deg, #000000 0%, #ff0080 100%)",color:"#ff0080",border:"2px solid #ff0080",shadow:"0 0 20px rgba(255, 0, 128, 1)"}},minimal:{debug:{emoji:"",label:"DEBUG",background:"#f7fafc",color:"#4a5568",border:"1px solid #e2e8f0",shadow:"none"},info:{emoji:"",label:"INFO",background:"#ebf8ff",color:"#2b6cb0",border:"1px solid #bee3f8",shadow:"none"},warn:{emoji:"",label:"WARN",background:"#fffbf0",color:"#c05621",border:"1px solid #fed7aa",shadow:"none"},error:{emoji:"",label:"ERROR",background:"#fef5f5",color:"#c53030",border:"1px solid #fca5a5",shadow:"none"},success:{emoji:"",label:"SUCCESS",background:"#f0fff4",color:"#2f855a",border:"1px solid #9ae6b4",shadow:"none"},critical:{emoji:"",label:"CRITICAL",background:"#fef5f5",color:"#e53e3e",border:"2px solid #f56565",shadow:"none"}},light:{debug:{emoji:"๐",label:"DEBUG",background:"linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%)",color:"#1565c0",border:"1px solid #90caf9",shadow:"0 1px 3px rgba(33, 150, 243, 0.2)"},info:{emoji:"โน๏ธ",label:"INFO",background:"linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%)",color:"#7b1fa2",border:"1px solid #ce93d8",shadow:"0 1px 3px rgba(156, 39, 176, 0.2)"},warn:{emoji:"โ ๏ธ",label:"WARN",background:"linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%)",color:"#f57c00",border:"1px solid #ffcc02",shadow:"0 1px 3px rgba(255, 152, 0, 0.2)"},error:{emoji:"โ",label:"ERROR",background:"linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%)",color:"#d32f2f",border:"1px solid #f44336",shadow:"0 1px 3px rgba(244, 67, 54, 0.2)"},success:{emoji:"โ
",label:"SUCCESS",background:"linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%)",color:"#388e3c",border:"1px solid #4caf50",shadow:"0 1px 3px rgba(76, 175, 80, 0.2)"},critical:{emoji:"๐จ",label:"CRITICAL",background:"linear-gradient(135deg, #fce4ec 0%, #f8bbd9 100%)",color:"#c2185b",border:"2px solid #e91e63",shadow:"0 2px 6px rgba(233, 30, 99, 0.3)"}},cyberpunk:{debug:{emoji:"๐ค",label:"DEBUG",background:"linear-gradient(135deg, #0d1b2a 0%, #415a77 100%)",color:"#00d4aa",border:"1px solid #00d4aa",shadow:"0 0 15px rgba(0, 212, 170, 0.4)"},info:{emoji:"๐",label:"INFO",background:"linear-gradient(135deg, #1b263b 0%, #0d1b2a 100%)",color:"#00b4d8",border:"1px solid #00b4d8",shadow:"0 0 15px rgba(0, 180, 216, 0.4)"},warn:{emoji:"โก",label:"WARN",background:"linear-gradient(135deg, #f72585 0%, #b5179e 100%)",color:"#ffff3f",border:"1px solid #ffff3f",shadow:"0 0 15px rgba(255, 255, 63, 0.4)"},error:{emoji:"๐",label:"ERROR",background:"linear-gradient(135deg, #7209b7 0%, #480ca8 100%)",color:"#ff006e",border:"1px solid #ff006e",shadow:"0 0 15px rgba(255, 0, 110, 0.6)"},success:{emoji:"โก",label:"SUCCESS",background:"linear-gradient(135deg, #003566 0%, #001d3d 100%)",color:"#00f5ff",border:"1px solid #00f5ff",shadow:"0 0 15px rgba(0, 245, 255, 0.4)"},critical:{emoji:"๐ฅ",label:"CRITICAL",background:"linear-gradient(135deg, #000000 0%, #ff0040 100%)",color:"#ff0040",border:"2px solid #ff0040",shadow:"0 0 25px rgba(255, 0, 64, 0.8)"}}},y={simple:{text:"๐ ADVANCED LOGGER v2.0.0 - State-of-the-art Console Styling ๐",style:"background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 12px 20px; border-radius: 8px; font-weight: bold; font-size: 14px;"},ascii:{text:`
|
|
3
|
+
___ ____ _ __ ___ _ __ _____ _____ ____ __ ___ _____ _____ _____ ____
|
|
4
|
+
/ _ \\ / __ \\| | / / / _ \\ | \\ | |/ ____| ____| _ \\ | | / _ \\ / ____| ___| _ | _ \\
|
|
5
|
+
/ /_\\ \\ / / _\` | |/ / / /_\\ \\ | \\| | | | |__ | | | | | | / / \\ \\| | __| |_ | |_| | |_) |
|
|
6
|
+
| _ || | (_| | < | _ | | . \` | | | __| | | | | | | | | | | | |_ | _| | /| _ <
|
|
7
|
+
| | | |\\ \\__,_|_|\\_\\ | | | | | |\\ | |___| |____| |_| | | |__\\ \\_/ /| |__| | |___| |\\ \\| |_) |
|
|
8
|
+
\\_| |_/ \\____/ \\_| |_/ |_| \\_|\\_____|______|____/ |_____/\\___/ \\_____|_____|_| \\_|____/
|
|
9
|
+
|
|
10
|
+
Advanced Logger v2.0.0 - Console Excellence`,style:'font-family: "Courier New", Consolas, Monaco, monospace; color: #667eea; font-size: 11px; line-height: 1.2;'},unicode:{text:`
|
|
11
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
12
|
+
โ ๐ ADVANCED LOGGER v2.0.0 โ
|
|
13
|
+
โ State-of-the-art Console Styling โ
|
|
14
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`,style:'font-family: "Courier New", Consolas, Monaco, monospace; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 15px; border-radius: 8px; font-size: 12px; line-height: 1.3;'},svg:{text:" ",style:`
|
|
15
|
+
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 80'><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='8'/><text x='200' y='30' text-anchor='middle' fill='white' font-family='monospace' font-size='14' font-weight='bold'>๐ ADVANCED LOGGER</text><text x='200' y='50' text-anchor='middle' fill='white' font-family='monospace' font-size='12'>State-of-the-art Console Styling</text><text x='200' y='65' text-anchor='middle' fill='white' font-family='monospace' font-size='10'>v2.0.0</text></svg>");
|
|
16
|
+
background-repeat: no-repeat;
|
|
17
|
+
background-size: 400px 80px;
|
|
18
|
+
padding: 40px 200px;
|
|
19
|
+
color: transparent;
|
|
20
|
+
display: inline-block;
|
|
21
|
+
border-radius: 8px;
|
|
22
|
+
`},animated:{text:" ๐ ADVANCED LOGGER v2.0.0 ",style:`
|
|
23
|
+
background: linear-gradient(-45deg, #667eea, #764ba2, #667eea, #764ba2);
|
|
24
|
+
background-size: 400% 400%;
|
|
25
|
+
color: white;
|
|
26
|
+
padding: 15px 25px;
|
|
27
|
+
border-radius: 10px;
|
|
28
|
+
font-weight: bold;
|
|
29
|
+
font-size: 14px;
|
|
30
|
+
font-family: monospace;
|
|
31
|
+
animation: gradientShift 3s ease infinite;
|
|
32
|
+
display: inline-block;
|
|
33
|
+
`}},I={default:{simple:"๐ ADVANCED LOGGER v2.0.0 - State-of-the-art Console Styling ๐",style:"background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 12px 20px; border-radius: 8px; font-weight: bold;"},dark:{simple:"๐ ADVANCED LOGGER v2.0.0 - Dark Mode Console Excellence ๐",style:"background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%); color: #e2e8f0; padding: 12px 20px; border-radius: 8px; font-weight: bold; border: 1px solid #4a5568;"},neon:{simple:"โก ADVANCED LOGGER v2.0.0 - Cyberpunk Console Experience โก",style:"background: linear-gradient(135deg, #0f3460 0%, #e94560 100%); color: #00ffff; padding: 12px 20px; border-radius: 8px; font-weight: bold; text-shadow: 0 0 10px #00ffff;"},minimal:{simple:"ADVANCED LOGGER v2.0.0 - Clean Console Styling",style:"background: #f7fafc; color: #2d3748; padding: 8px 16px; border: 1px solid #e2e8f0; border-radius: 4px; font-weight: 500;"},light:{simple:"โ๏ธ ADVANCED LOGGER v2.0.0 - Bright Console Styling โ๏ธ",style:"background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); color: #495057; padding: 12px 20px; border-radius: 8px; font-weight: bold; border: 1px solid #dee2e6;"},cyberpunk:{simple:"๐ค ADVANCED LOGGER v2.0.0 - Neural Console Interface ๐ค",style:"background: linear-gradient(135deg, #0d1b2a 0%, #415a77 100%); color: #00d4aa; padding: 12px 20px; border-radius: 8px; font-weight: bold; text-shadow: 0 0 10px #00d4aa; border: 1px solid #00d4aa;"}};function ee(){const s=navigator.userAgent,e=/Chrome/.test(s),t=/Firefox/.test(s),r=/Safari/.test(s)&&!/Chrome/.test(s),o=!!document.createElementNS&&!!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect;return typeof document<"u"&&"animationName"in document.createElement("div").style&&e?"animated":o&&(e||t)?"svg":e||t?"unicode":r?"ascii":"simple"}function j(s){const e=s||ee(),t=y[e];if(e==="animated"){const o=document.createElement("style");o.textContent=`
|
|
34
|
+
@keyframes gradientShift {
|
|
35
|
+
0% { background-position: 0% 50%; }
|
|
36
|
+
50% { background-position: 100% 50%; }
|
|
37
|
+
100% { background-position: 0% 50%; }
|
|
38
|
+
}
|
|
39
|
+
`,document.head.appendChild(o)}console.log(`%c${t.text}`,t.style);const r=["๐จ Advanced CSS Console Styling","๐ Automatic Stack Trace Parsing","๐ง Scoped Loggers & Prefixes","โก Performance Timers","๐ฏ Verbosity Filtering","๐ Extensible Handlers","๐ฑ Modern TypeScript Patterns","๐ค Export & Clipboard Support"];console.group("%cโจ Features","background: #f8f9fa; color: #495057; padding: 4px 8px; border-radius: 4px; font-weight: bold;"),r.forEach(o=>{console.log(`%c${o}`,"color: #6c757d; font-size: 13px;")}),console.groupEnd(),console.log("")}function A(s,e,t,r,o){const n=e[s],i=_(),a=new d().color("#666").size("11px").font("Monaco, Consolas, monospace").build(),l=new d().bg(n.background).color(n.color).border(n.border).shadow(n.shadow).padding("2px 8px").rounded("4px").bold().font("Monaco, Consolas, monospace").size("12px").build(),c=new d().bg("#2d3748").color("#e2e8f0").padding("2px 6px").rounded("3px").bold().font("Monaco, Consolas, monospace").size("11px").build(),m=new d().color("#2d3748").font("system-ui, -apple-system, sans-serif").size("14px").build(),u=new d().color("#718096").size("11px").font("Monaco, Consolas, monospace").build();let p=`%c${i.slice(11,23)} %c${n.emoji} ${n.label}`;const g=[a,l];return t&&(p+=` %c${t}`,g.push(c)),p+=` %c${r}`,g.push(m),o&&(p+=` %c(${o.file}:${o.line}:${o.column})`,g.push(u)),[p,...g]}function te(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function C(s){const e=document.createElement("div");return e.textContent=s,e.innerHTML}function oe(s,e=3){try{return JSON.stringify(s,(t,r)=>typeof r=="function"?"[Function]":r instanceof Error?`[Error: ${r.message}]`:r instanceof Date?r.toISOString():typeof r>"u"?"[undefined]":r,2)}catch{return String(s)}}class re{buffer=[];maxSize;groupDepth=0;currentGroup;constructor(e=x.DEFAULT_SIZE){this.maxSize=Math.min(Math.max(e,x.MIN_SIZE),x.MAX_SIZE)}handle(e,t,r,o){const n={id:te(),timestamp:o.timestamp,level:e,prefix:o.prefix,message:t,args:r,location:o.stackInfo,groupInfo:this.groupDepth>0?{depth:this.groupDepth,groupName:this.currentGroup}:void 0};this.buffer.push(n),this.buffer.length>this.maxSize&&this.buffer.shift()}setGroupInfo(e,t){this.groupDepth=e,this.currentGroup=t}getBufferStats(){const e=this.buffer.reduce((t,r)=>(t[r.level]=(t[r.level]||0)+1,t),{});return{size:this.buffer.length,maxSize:this.maxSize,usage:this.buffer.length/this.maxSize*100,oldestLog:this.buffer.length>0?new Date(this.buffer[0].timestamp):void 0,newestLog:this.buffer.length>0?new Date(this.buffer[this.buffer.length-1].timestamp):void 0,levelCounts:{debug:0,info:0,warn:0,error:0,critical:0,...e}}}clearBuffer(){this.buffer=[]}setBufferSize(e){this.maxSize=Math.min(Math.max(e,x.MIN_SIZE),x.MAX_SIZE),this.buffer.length>this.maxSize&&(this.buffer=this.buffer.slice(-this.maxSize))}filterLogs(e={}){let t=[...this.buffer];if(e.levels?.length&&(t=t.filter(r=>e.levels.includes(r.level))),e.prefixes?.length&&(t=t.filter(r=>r.prefix&&e.prefixes.includes(r.prefix))),e.excludePrefixes?.length&&(t=t.filter(r=>!r.prefix||!e.excludePrefixes.includes(r.prefix))),e.since){const r=L(e.since);t=t.filter(o=>new Date(o.timestamp)>=r)}if(e.until){const r=L(e.until);t=t.filter(o=>new Date(o.timestamp)<=r)}if(e.withStackTrace&&(t=t.filter(r=>r.location)),e.errorsOnly&&(t=t.filter(r=>r.level==="error"||r.level==="critical")),e.search){const r=e.search.toLowerCase();t=t.filter(o=>o.message.toLowerCase().includes(r)||o.args.some(n=>String(n).toLowerCase().includes(r)))}return e.last&&(t=t.slice(-e.last)),e.first&&(t=t.slice(0,e.first)),t}exportJSON(e,t){const r=e.map(o=>({timestamp:o.timestamp,level:o.level,prefix:o.prefix,message:o.message,...t.minimal?{}:{args:o.args.slice(1),location:o.location,groupInfo:o.groupInfo}}));return t.compact?JSON.stringify(r):JSON.stringify(r,null,2)}exportCSV(e,t){const r=t.minimal?["Timestamp","Level","Prefix","Message"]:["Timestamp","Level","Prefix","Message","File","Line","Args"],o=e.map(n=>{const i=[b(new Date(n.timestamp),"full"),n.level.toUpperCase(),n.prefix||"",`"${n.message.replace(/"/g,'""')}"`];return t.minimal||i.push(n.location?.file||"",n.location?.line?.toString()||"",`"${oe(n.args.slice(1)).replace(/"/g,'""')}"`),i});return[r.join(","),...o.map(n=>n.join(","))].join(`
|
|
40
|
+
`)}exportMarkdown(e,t){let o=`# Log Export - ${b(new Date,"full")}
|
|
41
|
+
|
|
42
|
+
`;if(!t.minimal){const n=this.getBufferStats();o+=`## Summary
|
|
43
|
+
`,o+=`- **Total logs**: ${e.length}
|
|
44
|
+
`,o+=`- **Errors**: ${n.levelCounts.error+n.levelCounts.critical}
|
|
45
|
+
`,o+=`- **Warnings**: ${n.levelCounts.warn}
|
|
46
|
+
|
|
47
|
+
`}if(t.groupBy==="level"){const n=e.reduce((i,a)=>(i[a.level]||(i[a.level]=[]),i[a.level].push(a),i),{});Object.entries(n).forEach(([i,a])=>{const l=this.getLevelEmoji(i);o+=`## ${l} ${i.toUpperCase()} (${a.length})
|
|
48
|
+
|
|
49
|
+
`,a.forEach(c=>{const m=b(new Date(c.timestamp),"time-only"),u=c.location?` (${c.location.file}:${c.location.line})`:"",p=c.prefix?` **${c.prefix}**:`:"";o+=`- \`${m}\`${p} ${c.message}${u}
|
|
50
|
+
`}),o+=`
|
|
51
|
+
`})}else o+=`## Logs
|
|
52
|
+
|
|
53
|
+
`,e.forEach(n=>{const i=b(new Date(n.timestamp),"time-only"),a=this.getLevelEmoji(n.level),l=n.location?` (${n.location.file}:${n.location.line})`:"",c=n.prefix?` **${n.prefix}**:`:"";o+=`- \`${i}\` ${a}${c} ${n.message}${l}
|
|
54
|
+
`});return o}exportPlain(e,t){return e.map(r=>{const o=b(new Date(r.timestamp),t.minimal?"time-only":"short"),n=r.level.toUpperCase().padEnd(8),i=r.prefix?`[${r.prefix}] `:"",a=!t.minimal&&r.location?` (${r.location.file}:${r.location.line})`:"";return`${o} ${n} ${i}${r.message}${a}`}).join(`
|
|
55
|
+
`)}exportHTML(e,t){const r=`Log Export - ${b(new Date,"full")}`;let o=`<!DOCTYPE html>
|
|
56
|
+
<html lang="en">
|
|
57
|
+
<head>
|
|
58
|
+
<meta charset="UTF-8">
|
|
59
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
60
|
+
<title>${r}</title>
|
|
61
|
+
<style>
|
|
62
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 20px; line-height: 1.6; }
|
|
63
|
+
.header { border-bottom: 2px solid #ddd; padding-bottom: 20px; margin-bottom: 20px; }
|
|
64
|
+
.log-entry { margin: 5px 0; padding: 8px; border-radius: 4px; font-family: 'Monaco', 'Consolas', monospace; }
|
|
65
|
+
.timestamp { color: #666; font-size: 0.9em; }
|
|
66
|
+
.level { font-weight: bold; padding: 2px 6px; border-radius: 3px; margin: 0 8px; }
|
|
67
|
+
.prefix { background: #2d3748; color: #e2e8f0; padding: 2px 6px; border-radius: 3px; margin: 0 8px; }
|
|
68
|
+
.location { color: #718096; font-size: 0.9em; }
|
|
69
|
+
.debug { background: #f0f4ff; }
|
|
70
|
+
.info { background: #f0f9ff; }
|
|
71
|
+
.warn { background: #fffbeb; }
|
|
72
|
+
.error { background: #fef2f2; }
|
|
73
|
+
.critical { background: #fef2f2; border-left: 4px solid #dc2626; }
|
|
74
|
+
.level.debug { background: #667eea; color: white; }
|
|
75
|
+
.level.info { background: #74b9ff; color: white; }
|
|
76
|
+
.level.warn { background: #fdcb6e; color: #2d3436; }
|
|
77
|
+
.level.error { background: #e84393; color: white; }
|
|
78
|
+
.level.critical { background: #ff3838; color: white; }
|
|
79
|
+
</style>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<div class="header">
|
|
83
|
+
<h1>${r}</h1>
|
|
84
|
+
<p>Generated by Advanced Logger v2.0.0</p>
|
|
85
|
+
</div>
|
|
86
|
+
<div class="logs">`;return e.forEach(n=>{const i=b(new Date(n.timestamp),"full"),a=n.location?` <span class="location">(${C(n.location.file)}:${n.location.line})</span>`:"",l=n.prefix?` <span class="prefix">${C(n.prefix)}</span>`:"";o+=`
|
|
87
|
+
<div class="log-entry ${n.level}">
|
|
88
|
+
<span class="timestamp">${i}</span>
|
|
89
|
+
<span class="level ${n.level}">${n.level.toUpperCase()}</span>
|
|
90
|
+
${l}
|
|
91
|
+
<span class="message">${C(n.message)}</span>
|
|
92
|
+
${a}
|
|
93
|
+
</div>`}),o+=`
|
|
94
|
+
</div>
|
|
95
|
+
</body>
|
|
96
|
+
</html>`,o}getLevelEmoji(e){return{debug:"๐",info:"โน๏ธ",warn:"โ ๏ธ",error:"โ",critical:"๐ฅ"}[e]||""}export(e,t={},r={}){const o=this.filterLogs(t);let n;switch(e){case"json":n=this.exportJSON(o,r);break;case"csv":n=this.exportCSV(o,r);break;case"markdown":n=this.exportMarkdown(o,r);break;case"plain":n=this.exportPlain(o,r);break;case"html":n=this.exportHTML(o,r);break;default:throw new Error(`Unsupported export format: ${e}`)}return{format:e,data:n,metadata:{totalLogs:this.buffer.length,filteredLogs:o.length,exportedAt:new Date().toISOString(),filters:t,options:r}}}async copyToClipboard(e,t={},r={}){const o=this.export(e,t,r);try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(o.data),!0;{const n=document.createElement("textarea");n.value=o.data,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.focus(),n.select();const i=document.execCommand("copy");return document.body.removeChild(n),i}}catch(n){return console.error("Failed to copy to clipboard:",n),!1}}getAllLogs(){return[...this.buffer]}}class ne{commands=new Map;registerCommand(e){this.commands.set(e.name,e)}getCommands(){return Array.from(this.commands.values())}getCommand(e){return this.commands.get(e)}async processCommand(e,t){if(!e.startsWith("/")){t.error("Invalid command. Commands must start with /");return}const r=e.slice(1).split(" "),o=r[0],n=r.slice(1).join(" "),i=this.commands.get(o);if(!i){t.error(`Unknown command: ${o}. Type /help for available commands.`);return}try{await i.execute(n,t)}catch(a){t.error(`Command '${o}' failed:`,a)}}getSuggestions(e){return Array.from(this.commands.keys()).filter(r=>r.startsWith(e))}}class se{name="config";description="Show or update logger configuration";usage="/config [json|key=value,...]";execute(e,t){if(!e){this.showStatus(t);return}try{if(e.startsWith("{")){const r=JSON.parse(e);this.applyConfig(r,t)}else{const r=e.split(",").map(n=>n.trim().split("=")),o={};r.forEach(([n,i])=>{n&&i&&(o[n.trim()]=i.trim().replace(/["']/g,""))}),this.applyConfig(o,t)}}catch(r){t.error("Invalid config format. Use JSON or key=value pairs:",r),t.info('Examples: /config {"theme":"dark"} or /config theme=neon,verbosity=debug')}}showStatus(e){const t={theme:e.getConfig().theme||"default",verbosity:e.getConfig().verbosity,colors:e.getConfig().enableColors,timestamps:e.getConfig().enableTimestamps,stackTrace:e.getConfig().enableStackTrace,globalPrefix:e.getConfig().globalPrefix||"none",bannerType:e.getConfig().bannerType||"simple",handlers:e.getHandlers().length};e.group("โ๏ธ Logger Configuration"),e.table(t),e.groupEnd()}applyConfig(e,t){const r=["theme","verbosity","enableColors","enableTimestamps","enableStackTrace","globalPrefix","bannerType"],o=[];Object.entries(e).forEach(([n,i])=>{r.includes(n)?n==="theme"&&typeof i=="string"?(t.setTheme(i),o.push(`${n}=${i}`)):n==="bannerType"&&typeof i=="string"?(t.setBannerType(i),o.push(`${n}=${i}`)):n==="verbosity"?(t.setVerbosity(i),o.push(`${n}=${i}`)):n==="globalPrefix"?(t.setGlobalPrefix(i),o.push(`${n}=${i}`)):(t.updateConfig({[n]:i}),o.push(`${n}=${i}`)):t.warn(`Invalid config key: ${n}`)}),o.length>0&&t.success(`Configuration updated: ${o.join(", ")}`)}}class ie{name="themes";description="Show available theme presets";usage="/themes";execute(e,t){t.group("๐จ Available Themes"),Object.keys(h).forEach(r=>{const o=h[r],n=new d().bg(o.info.background).color(o.info.color).padding("4px 8px").rounded("4px").border(o.info.border).build();console.log(`%c${r}`,n,`- ${r} theme preview`)}),t.groupEnd()}}class ae{name="banners";description="Show available banner types";usage="/banners";execute(e,t){t.group("๐ผ๏ธ Available Banner Types"),Object.keys(y).forEach(r=>{const o=y[r];console.log(`%c${r}`,"font-weight: bold; color: #667eea;"),console.log("%cPreview:","color: #666; font-size: 12px;"),r==="simple"?console.log(`%c${o.text}`,o.style):r==="ascii"?console.log(`%c${o.text.split(`
|
|
97
|
+
`).slice(1,4).join(`
|
|
98
|
+
`)}...`,"font-family: monospace; color: #667eea; font-size: 10px;"):r==="unicode"?console.log(`%c${o.text}`,o.style):console.log(`%c${r} banner`,"color: #666; font-style: italic;")}),t.groupEnd()}}class le{name="banner";description="Change or show current banner type";usage="/banner [type]";execute(e,t){if(!e){t.showBanner();return}e in y?(t.setBannerType(e),t.showBanner()):t.error(`Invalid banner type: ${e}. Available: ${Object.keys(y).join(", ")}`)}}class ce{name="status";description="Show current logger status and configuration";usage="/status";execute(e,t){const r={theme:t.getConfig().theme||"default",verbosity:t.getConfig().verbosity,colors:t.getConfig().enableColors,timestamps:t.getConfig().enableTimestamps,stackTrace:t.getConfig().enableStackTrace,globalPrefix:t.getConfig().globalPrefix||"none",bannerType:t.getConfig().bannerType||"simple",handlers:t.getHandlers().length,bufferSize:t.getConfig().bufferSize||1e3};t.group("โ๏ธ Logger Configuration"),t.table(r),t.groupEnd();const o=t.getExportHandler();if(o){const n=o.getBufferStats();t.group("๐ Buffer Statistics"),t.table({size:`${n.size}/${n.maxSize}`,usage:`${n.usage.toFixed(1)}%`,oldestLog:n.oldestLog?.toISOString()||"None",newestLog:n.newestLog?.toISOString()||"None",errorCount:n.levelCounts.error+n.levelCounts.critical,warningCount:n.levelCounts.warn}),t.groupEnd()}}}class de{name="reset";description="Reset logger configuration to defaults";usage="/reset";execute(e,t){t.resetConfig()}}class fe{name="demo";description="Show comprehensive feature demonstration";usage="/demo";execute(e,t){t.group("๐ช Advanced Logger Demo"),t.debug("Debug message with detailed information"),t.info("Informational message about system state"),t.warn("Warning about deprecated feature"),t.error("Error processing user request"),t.success("Operation completed successfully"),t.critical("Critical system failure detected"),t.group("๐ Advanced Features Demo"),t.table([{feature:"Styled Console",status:"โ
Active",performance:"Excellent"},{feature:"Theme System",status:"โ
Active",performance:"Great"},{feature:"CLI Interface",status:"โ
Active",performance:"Good"},{feature:"Export System",status:"โ
Active",performance:"Excellent"}]),t.time("demo-operation"),setTimeout(()=>{t.timeEnd("demo-operation")},100),t.logWithSVG("SVG Demo"),t.logAnimated("๐ Animated Logger Demo ๐",2),t.groupEnd(),t.groupEnd(),t.info("Demo completed! Check the console for styled output.")}}function R(s){const e={},t={};let r;if(!s.trim())return{filters:e,options:t};const o=s.match(/(?:[^\s"]+|"[^"]*")+/g)||[];for(let n=0;n<o.length;n++){const i=o[n];if(n===0&&!i.startsWith("--")&&i in E){r=i;continue}if(i.startsWith("--")){const[a,l]=i.slice(2).split("=");switch(a){case"level":case"levels":l&&(e.levels=l.split(",").map(c=>c.trim()));break;case"since":l&&(e.since=l);break;case"until":l&&(e.until=l);break;case"prefix":case"prefixes":l&&(e.prefixes=l.split(",").map(c=>c.trim()));break;case"exclude-prefix":case"exclude-prefixes":l&&(e.excludePrefixes=l.split(",").map(c=>c.trim()));break;case"last":l&&(e.last=parseInt(l,10));break;case"first":l&&(e.first=parseInt(l,10));break;case"search":l&&(e.search=l.replace(/['"]/g,""));break;case"with-stack":e.withStackTrace=!0;break;case"errors-only":e.errorsOnly=!0;break;case"group-by":l&&(e.groupBy=l,t.groupBy=l);break;case"minimal":t.minimal=!0;break;case"compact":t.compact=!0;break;case"styled":t.styled=!0;break}}}return{filters:e,options:t,format:r}}class pe{name="export";description="Export logs to various formats";usage="/export <format> [--filter=value] [--option]";execute(e,t){const r=t.getExportHandler();if(!r){t.error("Export handler not available. Make sure ExportLogHandler is registered.");return}const{filters:o,options:n,format:i}=R(e);if(!i){t.error("Format required. Available formats: "+Object.keys(E).join(", ")),t.info("Usage: /export <format> [--filter=value]"),t.info("Example: /export json --level=error,warn --last=50");return}try{const a=r.export(i,o,n);t.success(`โ
Export completed: ${a.metadata.filteredLogs} logs exported in ${i} format`),a.data.length<1e3?(t.group(`๐ Preview (${i.toUpperCase()})`),console.log(a.data),t.groupEnd()):t.info(`๐ Export size: ${(a.data.length/1024).toFixed(2)}KB`),t.table({format:a.format,totalLogs:a.metadata.totalLogs,filtered:a.metadata.filteredLogs,exported:a.metadata.exportedAt})}catch(a){t.error("Export failed:",a)}}}class ue{name="copy";description="Copy logs to clipboard";usage="/copy <format> [--filter=value] [--option]";async execute(e,t){const r=t.getExportHandler();if(!r){t.error("Export handler not available. Make sure ExportLogHandler is registered.");return}const{filters:o,options:n,format:i}=R(e);if(!i){t.error("Format required. Available formats: "+Object.keys(E).join(", ")),t.info("Usage: /copy <format> [--filter=value]"),t.info("Example: /copy plain --level=error --last=25");return}try{if(await r.copyToClipboard(i,o,n)){const l=r.export(i,o,n);t.success(`๐ Copied ${l.metadata.filteredLogs} logs to clipboard (${i} format)`)}else t.error("Failed to copy to clipboard. Browser may not support clipboard API.")}catch(a){t.error("Copy failed:",a)}}}class ge{name="buffer-size";description="Set log buffer size";usage="/buffer-size <size>";execute(e,t){const r=t.getExportHandler();if(!r){t.error("Export handler not available.");return}const o=parseInt(e.trim(),10);if(isNaN(o)||o<=0){t.error("Invalid buffer size. Must be a positive number."),t.info("Example: /buffer-size 2000");return}r.setBufferSize(o),t.success(`Buffer size set to ${o}`)}}class me{name="clear-buffer";description="Clear the log buffer";usage="/clear-buffer";execute(e,t){const r=t.getExportHandler();if(!r){t.error("Export handler not available.");return}const o=r.getBufferStats();r.clearBuffer(),t.success(`โ
Buffer cleared. Removed ${o.size} log entries.`)}}class be{name="buffer-info";description="Show buffer statistics and information";usage="/buffer-info";execute(e,t){const r=t.getExportHandler();if(!r){t.error("Export handler not available.");return}const o=r.getBufferStats();t.group("๐ Buffer Information"),t.table({size:`${o.size}/${o.maxSize}`,usage:`${o.usage.toFixed(1)}%`,oldestLog:o.oldestLog?.toLocaleString()||"None",newestLog:o.newestLog?.toLocaleString()||"None"}),t.group("๐ Log Level Counts"),t.table(o.levelCounts),t.groupEnd(),t.groupEnd()}}class he{name="help";description="Show CLI help and available commands";usage="/help [command]";execute(e,t){const r=new d().bg("linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%)").color("#495057").padding("15px 20px").rounded("8px").border("1px solid #dee2e6").font("Monaco, Consolas, monospace").size("13px").build();console.log(`%c
|
|
99
|
+
โญโโโโโโโโโโโโโโโ ADVANCED LOGGER CLI COMMANDS โโโโโโโโโโโโโโโโโโฎ
|
|
100
|
+
โ โ
|
|
101
|
+
โ CONFIGURATION โ
|
|
102
|
+
โ /config Show current configuration โ
|
|
103
|
+
โ /config {json} Apply JSON configuration โ
|
|
104
|
+
โ /config key=val Apply key-value configuration โ
|
|
105
|
+
โ /themes Show available themes โ
|
|
106
|
+
โ /banners Show available banner types โ
|
|
107
|
+
โ /banner [type] Change/show banner type โ
|
|
108
|
+
โ /status Show logger status & buffer stats โ
|
|
109
|
+
โ /demo Show feature demonstration โ
|
|
110
|
+
โ /reset Reset to default configuration โ
|
|
111
|
+
โ โ
|
|
112
|
+
โ EXPORT & CLIPBOARD โ
|
|
113
|
+
โ /export <format> Export logs (json|csv|md|plain|html) โ
|
|
114
|
+
โ /copy <format> Copy logs to clipboard โ
|
|
115
|
+
โ /buffer-size N Set log buffer size โ
|
|
116
|
+
โ /buffer-info Show buffer statistics โ
|
|
117
|
+
โ /clear-buffer Clear stored logs โ
|
|
118
|
+
โ โ
|
|
119
|
+
โ EXPORT FILTERS (for export/copy commands) โ
|
|
120
|
+
โ --level error,warn Filter by log levels โ
|
|
121
|
+
โ --since 2h Logs from last 2 hours โ
|
|
122
|
+
โ --until 1h Logs until 1 hour ago โ
|
|
123
|
+
โ --prefix API,DB Filter by prefixes โ
|
|
124
|
+
โ --exclude-prefix INT Exclude prefixes โ
|
|
125
|
+
โ --last 50 Last 50 logs only โ
|
|
126
|
+
โ --first 25 First 25 logs only โ
|
|
127
|
+
โ --search "error" Search in log messages โ
|
|
128
|
+
โ --with-stack Only logs with stack traces โ
|
|
129
|
+
โ --errors-only Only error + critical logs โ
|
|
130
|
+
โ --group-by level Group by level/prefix/hour โ
|
|
131
|
+
โ โ
|
|
132
|
+
โ EXPORT OPTIONS โ
|
|
133
|
+
โ --minimal Minimal output format โ
|
|
134
|
+
โ --compact Remove extra whitespace โ
|
|
135
|
+
โ --styled Include styling (HTML format) โ
|
|
136
|
+
โ โ
|
|
137
|
+
โโโโโโโโโโโโโโโโโโโโโ CONFIGURATION OPTIONS โโโโโโโโโโโโโโโโโโค
|
|
138
|
+
โ โ
|
|
139
|
+
โ theme: default | dark | light | neon | minimal | cyberpunkโ
|
|
140
|
+
โ bannerType: simple | ascii | unicode | svg | animated โ
|
|
141
|
+
โ verbosity: debug | info | warn | error | critical | silentโ
|
|
142
|
+
โ enableColors: true | false โ
|
|
143
|
+
โ enableTimestamps: true | false โ
|
|
144
|
+
โ enableStackTrace: true | false โ
|
|
145
|
+
โ globalPrefix: "string" โ
|
|
146
|
+
โ bufferSize: number (50-10000) โ
|
|
147
|
+
โ โ
|
|
148
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโ EXAMPLES โโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
149
|
+
โ โ
|
|
150
|
+
โ Basic Configuration: โ
|
|
151
|
+
โ /config {"theme":"dark","verbosity":"debug"} โ
|
|
152
|
+
โ /config theme=neon,bufferSize=2000 โ
|
|
153
|
+
โ /banner animated Change to animated banner โ
|
|
154
|
+
โ โ
|
|
155
|
+
โ Export Examples: โ
|
|
156
|
+
โ /export json --level=error,warn --last=25 โ
|
|
157
|
+
โ /export csv --since=2h --prefix=API โ
|
|
158
|
+
โ /export markdown --group-by=level --errors-only โ
|
|
159
|
+
โ /export html --styled --since=1h โ
|
|
160
|
+
โ โ
|
|
161
|
+
โ Clipboard Examples: โ
|
|
162
|
+
โ /copy plain --minimal --last=10 โ
|
|
163
|
+
โ /copy json --search="authentication" --compact โ
|
|
164
|
+
โ /copy csv --since=30m --exclude-prefix=DEBUG โ
|
|
165
|
+
โ โ
|
|
166
|
+
โ Buffer Management: โ
|
|
167
|
+
โ /buffer-size 5000 Increase buffer to 5000 logs โ
|
|
168
|
+
โ /buffer-info Show detailed buffer statistics โ
|
|
169
|
+
โ /clear-buffer Clear all stored logs โ
|
|
170
|
+
โ โ
|
|
171
|
+
โ Time Formats: โ
|
|
172
|
+
โ --since=2h 2 hours ago โ
|
|
173
|
+
โ --since=30m 30 minutes ago โ
|
|
174
|
+
โ --since=1d 1 day ago โ
|
|
175
|
+
โ --since="2024-01-01T10:00:00Z" Specific ISO date โ
|
|
176
|
+
โ โ
|
|
177
|
+
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ`,r),t.group("๐ก Quick Tips"),["Use /demo to see all logger features in action","Logs are automatically stored in a circular buffer for export","Export formats: JSON (structured), CSV (Excel), Markdown (readable), Plain (simple), HTML (styled)","Time filters support relative (2h, 30m) and absolute (ISO) formats",'Combine multiple filters: /export json --level=error --since=1h --search="auth"',"Use /copy for quick clipboard access instead of /export"].forEach(i=>{t.info(`โข ${i}`)}),t.groupEnd()}}function xe(){const s=new ne;return s.registerCommand(new he),s.registerCommand(new se),s.registerCommand(new ie),s.registerCommand(new ae),s.registerCommand(new le),s.registerCommand(new ce),s.registerCommand(new de),s.registerCommand(new fe),s.registerCommand(new pe),s.registerCommand(new ue),s.registerCommand(new ge),s.registerCommand(new me),s.registerCommand(new be),s}let w=h.default;class v{config;scopedPrefix;handlers=[];timers=new Map;groupDepth=0;exportHandler;cliProcessor;constructor(e={}){this.config={...T,...e},this.config.bufferSize&&(this.exportHandler=new re(this.config.bufferSize),this.handlers.push(this.exportHandler)),this.cliProcessor=xe()}getConfig(){return{...this.config}}updateConfig(e){this.config={...this.config,...e}}setGlobalPrefix(e){this.config.globalPrefix=e}setVerbosity(e){this.config.verbosity=e}setTheme(e){if(e in h){if(w=h[e],this.config.theme=e,e in I){const t=I[e];console.log(`%c${t.simple}`,t.style)}this.success(`Theme changed to: ${e}`)}else this.error(`Invalid theme: ${e}. Available themes:`,Object.keys(h))}setBannerType(e){this.config.bannerType=e,this.success(`Banner type changed to: ${e}`)}resetConfig(){this.config={...T},w=h.default,this.success("Logger configuration reset to defaults")}createScopedLogger(e){const t=new v(this.config);return t.scopedPrefix=e,t.handlers=[...this.handlers],t.exportHandler=this.exportHandler,t}addHandler(e){this.handlers.push(e)}getHandlers(){return[...this.handlers]}getExportHandler(){return this.exportHandler}shouldLog(e){if(this.config.verbosity==="silent")return!1;const t={debug:0,info:1,warn:2,error:3,critical:4};return t[e]>=t[this.config.verbosity]}getEffectivePrefix(){const e=[this.config.globalPrefix,this.scopedPrefix].filter(Boolean);return e.length>0?e.join(":"):void 0}log(e,...t){if(!this.shouldLog(e))return;const r=this.config.enableStackTrace?k():null,o=this.getEffectivePrefix(),n=t.length>0?String(t[0]):"",i=t.slice(1),[a,...l]=A(e,w,o,n,r),m=" ".repeat(this.groupDepth)+a;i.length>0?console.log(m,...l,...i):console.log(m,...l),this.exportHandler&&this.exportHandler.setGroupInfo(this.groupDepth);const u={timestamp:_(),level:e,prefix:o,stackInfo:r||void 0};this.handlers.forEach(p=>{try{p.handle(e,n,t,u)}catch(g){console.error("Log handler failed:",g)}})}debug(...e){this.log("debug",...e)}info(...e){this.log("info",...e)}warn(...e){this.log("warn",...e)}error(...e){this.log("error",...e)}success(...e){if(!this.shouldLog("info"))return;const t=this.config.enableStackTrace?k():null,r=this.getEffectivePrefix(),o=e.length>0?String(e[0]):"",n=e.slice(1),[i,...a]=A("info",w,r,o,t),l=w.success,c=i.replace(/โน๏ธ INFO/,`${l.emoji} ${l.label}`),u=" ".repeat(this.groupDepth)+c;n.length>0?console.log(u,...a,...n):console.log(u,...a);const p={timestamp:_(),level:"info",prefix:r,stackInfo:t||void 0};this.handlers.forEach(g=>{try{g.handle("info",o,e,p)}catch(K){console.error("Log handler failed:",K)}})}trace(...e){this.log("debug",...e),this.shouldLog("debug")&&console.trace(...e)}critical(...e){this.log("critical",...e)}table(e,t){if(!this.shouldLog("info"))return;const r=this.getEffectivePrefix(),o=S.accent().build(),n=`%c๐ TABLE${r?` [${r}]`:""}`;console.log(n,o),t?console.table(e,t):console.table(e)}group(e,t=!1){const r=new d().bg("linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%)").color("#1565c0").border("1px solid #90caf9").padding("4px 12px").rounded("6px").bold().build(),o=`%c๐ ${e}`;t?console.groupCollapsed(o,r):console.group(o,r),this.groupDepth++}groupEnd(){this.groupDepth>0&&(console.groupEnd(),this.groupDepth--)}time(e){const t={label:e,startTime:performance.now()};this.timers.set(e,t);const r=S.warning().build();console.log(`%cโฑ๏ธ Timer started: ${e}`,r)}timeEnd(e){const t=this.timers.get(e);if(!t){this.warn(`Timer '${e}' does not exist`);return}const r=performance.now()-t.startTime;this.timers.delete(e);const o=S.success().build();console.log(`%cโฑ๏ธ Timer ended: ${e} - ${r.toFixed(2)}ms`,o)}showBanner(e){j(e||this.config.bannerType)}logWithSVG(e,t,r={}){const{width:o=300,height:n=60,padding:i="30px 150px"}=r;let a="";if(t)a=`data:image/svg+xml,${encodeURIComponent(t)}`;else{const c=`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${o} ${n}'><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='${o/2}' y='${n/2+5}' text-anchor='middle' fill='white' font-family='monospace' font-size='14' font-weight='bold'>${e}</text></svg>`;a=`data:image/svg+xml,${encodeURIComponent(c)}`}const l=new d().bg(`url("${a}") no-repeat center center`).padding(i).color("transparent").rounded("4px").build();console.log(`%c${e}`,l)}logAnimated(e,t=3){if(!document.getElementById("logger-animations")){const o=document.createElement("style");o.id="logger-animations",o.textContent=`
|
|
178
|
+
@keyframes loggerGradient {
|
|
179
|
+
0% { background-position: 0% 50%; }
|
|
180
|
+
50% { background-position: 100% 50%; }
|
|
181
|
+
100% { background-position: 0% 50%; }
|
|
182
|
+
}
|
|
183
|
+
`,document.head.appendChild(o)}const r=new d().bg("linear-gradient(-45deg, #667eea, #764ba2, #667eea, #764ba2)").css("background-size","400% 400%").color("#ffffff").padding("12px 20px").rounded("8px").bold().font("Monaco, Consolas, monospace").animation(`loggerGradient ${t}s ease infinite`).display("inline-block").build();console.log(`%c${e}`,r)}logGrouped(e,t){try{const r=Object.groupBy?.(e,t)||e.reduce((o,n)=>{const i=t(n);return o[i]||(o[i]=[]),o[i].push(n),o},{});Object.entries(r).forEach(([o,n])=>{this.group(`Group: ${o}`),this.table(n),this.groupEnd()})}catch{this.info("Grouped data:",e)}}async cli(e){if(!this.cliProcessor){this.error("CLI processor not initialized");return}await this.cliProcessor.processCommand(e,this)}}const f=new v({verbosity:"info",enableColors:!0,enableTimestamps:!0,enableStackTrace:!0,bufferSize:1e3});j();const we=(...s)=>f.debug(...s),$=(...s)=>f.info(...s),N=(...s)=>f.warn(...s),ye=(...s)=>f.error(...s),z=(...s)=>f.success(...s),Se=(...s)=>f.trace(...s),Ce=(...s)=>f.critical(...s),_e=(s,e)=>f.table(s,e),G=(s,e)=>f.group(s,e),P=()=>f.groupEnd(),Ee=s=>f.time(s),ve=s=>f.timeEnd(s),D=s=>f.createScopedLogger(s),$e=s=>f.setTheme(s),ke=s=>f.cli(s);console.log("Advanced Logger script loaded. Test functions are now available.");function B(){we("This is a debug message.",{user:"test",id:123})}function M(){$("This is an info message with an object.",{data:"payload"})}function F(){N("This is a warning message about a deprecated API.")}function U(){ye("This is an error message.",new Error("Failed to fetch resource."))}function H(){z("Operation completed successfully.")}function V(){Ce("This is a CRITICAL message. System integrity compromised!")}function W(){_e([{feature:"Debug Log",status:"Implemented",priority:"Low"},{feature:"Info Log",status:"Implemented",priority:"Medium"},{feature:"Warning Log",status:"Implemented",priority:"High"}])}function J(){G("User Authentication Flow",!0),$("User 'testuser' attempting to log in..."),N("Password nearing expiration."),z("Login successful."),P()}function Z(){Ee("dataProcessing"),setTimeout(()=>{ve("dataProcessing")},750)}function X(){$("Demonstrating scoped loggers...");const s=D("API");s.info("Fetching user data..."),D("UI").debug("Rendering user profile component."),s.success("User data fetched successfully."),s.error("Failed to update settings.")}function q(){function s(){function e(){Se("Trace from a deeply nested function.")}e()}s()}function Te(){G("๐ Demonstrating All Logger Features"),B(),M(),F(),U(),H(),V(),W(),J(),Z(),X(),q(),P()}typeof window<"u"&&(window.testDebug=B,window.testInfo=M,window.testWarn=F,window.testError=U,window.testSuccess=H,window.testCritical=V,window.testTable=W,window.testGrouping=J,window.testTiming=Z,window.testScopedLogger=X,window.testTrace=q,window.testAllFeatures=Te,window.cli=ke,window.setTheme=$e,console.log('%c๐ Logger CLI Available! Try: cli("/help")',"background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 8px 12px; border-radius: 4px; font-weight: bold;"));
|