Skip to content

Commit 72b314f

Browse files
committed
chore: wip
chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip chore: wip
1 parent 024eca5 commit 72b314f

23 files changed

+1667
-1953
lines changed

.vscode/dictionary.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ booleanish
44
bumpp
55
bunfig
66
bunx
7+
chacha
78
changelogen
89
changelogithub
910
codecov

README.md

+35-15
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,25 @@
1212
1313
## Features
1414

15-
- 🎨 Rich Colored Output
16-
- ⚡ Performance Tracking
17-
- 📊 Multiple Log Levels
18-
- 🎯 Domain-specific Logging
19-
- 🔄 Format String Support
20-
- 📝 Automatic Log Rotation
21-
- 🛠️ CLI & Library Support
22-
- 🌐 Browser & Server Compatible
23-
- 💪 TypeScript Support
15+
- 🚀 High-Performance Logging
16+
- 🎯 Domain-Specific Namespaces
17+
- 🤞 Fingers-Crossed Log Buffering
18+
- 🔄 Automatic Log Rotation & Cleanup
19+
- 🔐 Encrypted Log Storage
20+
21+
### Output & Formatting
22+
23+
- 🎨 Rich Color-Coded Console Output
24+
- 📊 Multiple Log Levels _(debug, info, success, warn, error)_
25+
- 🔠 Format String Support _(%s, %d, %j, etc.)_
26+
- ⚡ Built-in Performance Tracking
27+
28+
### Platform Support
29+
30+
- 🌐 Universal _(Browser + Server)_
31+
- 🛠️ CLI & Library APIs
32+
- 💻 First-Class TypeScript Support
33+
- 📦 Zero External Dependencies
2434

2535
## Install
2636

@@ -44,8 +54,13 @@ import { Logger } from 'clarity'
4454
const logger = new Logger('parser', {
4555
// Optional configuration
4656
maxLogSize: 5 * 1024 * 1024, // 5MB
47-
maxLogFiles: 10,
48-
compressLogs: true,
57+
58+
rotation: {
59+
maxLogFiles: 10,
60+
compress: true,
61+
},
62+
63+
encrypted: true,
4964
})
5065

5166
// Basic logging
@@ -152,14 +167,19 @@ const logger = new Logger('app', {
152167
verbose: true,
153168

154169
// Output Format
155-
json: false,
170+
format: 'json',
156171
timestamp: true,
157172
colors: true,
158173

159174
// Log Rotation
160-
maxLogSize: 10 * 1024 * 1024, // 10MB
161-
maxLogFiles: 5,
162-
compressLogs: true,
175+
rotation: {
176+
frequency: 'daily',
177+
maxLogSize: 10 * 1024 * 1024, // 10MB
178+
maxLogFiles: 5,
179+
compress: true,
180+
},
181+
182+
encrypt: true,
163183
logDirectory: '~/.clarity/logs',
164184
})
165185
```
File renamed without changes.

src/cli/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@ -1,50 +0,0 @@
12
export interface WatchOptions {
23
level?: 'debug' | 'info' | 'warning' | 'error'
34
name?: string

src/config.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import type { ClarityConfig } from './types'
22
import { loadConfig } from 'bunfig'
33

4+
const defaultRotationConfig: ClarityConfig['rotation'] = {
5+
frequency: 'daily',
6+
maxSize: 10 * 1024 * 1024,
7+
maxFiles: 5,
8+
compress: false,
9+
rotateHour: 0,
10+
rotateMinute: 0,
11+
rotateDayOfWeek: 0,
12+
rotateDayOfMonth: 1,
13+
encrypt: false,
14+
}
15+
416
export const defaultConfig: ClarityConfig = {
517
level: 'info',
618
defaultName: 'app',
7-
json: false,
819
timestamp: true,
920
colors: true,
1021
format: 'text',
1122
maxLogSize: 10 * 1024 * 1024,
12-
maxLogFiles: 5,
13-
compressLogs: true,
1423
logDatePattern: 'YYYY-MM-DD',
1524
logDirectory: '',
25+
rotation: defaultRotationConfig,
1626
verbose: false,
1727
}
1828

src/formatters/index.ts

-18
This file was deleted.

src/formatters/json.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { LogEntry } from '../types'
2-
import type { LogFormatter } from './types'
1+
import type { Formatter, LogEntry } from '../types'
32
import process from 'node:process'
43
import { isServerProcess } from '../utils'
54

6-
export class JsonFormatter implements LogFormatter {
5+
export class JsonFormatter implements Formatter {
76
async format(entry: LogEntry): Promise<string> {
87
const isServer = await isServerProcess()
98
const metadata = await this.getMetadata(isServer)
@@ -19,20 +18,25 @@ export class JsonFormatter implements LogFormatter {
1918

2019
private async getMetadata(isServer: boolean) {
2120
if (isServer) {
22-
// Server environment
2321
const { hostname } = await import('node:os')
2422
return {
2523
pid: process.pid,
2624
hostname: hostname(),
2725
environment: process.env.NODE_ENV || 'development',
26+
platform: process.platform,
27+
version: process.version,
2828
}
2929
}
3030

31-
// Browser environment
3231
return {
3332
userAgent: navigator.userAgent,
3433
hostname: window.location.hostname || 'browser',
3534
environment: process.env.NODE_ENV || 'development',
35+
viewport: {
36+
width: window.innerWidth,
37+
height: window.innerHeight,
38+
},
39+
language: navigator.language,
3640
}
3741
}
3842
}

src/formatters/text.ts

+30-36
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
1-
import type { LogEntry } from '../types'
2-
import type { LogFormatter } from './types'
1+
import type { ClarityConfig, Formatter, LogEntry, LogLevel } from '../types'
32
import * as colors from '../colors'
3+
import { format } from '../format'
44

5-
export class TextFormatter implements LogFormatter {
6-
constructor(private useColors: boolean = true) { }
5+
export class TextFormatter implements Formatter {
6+
constructor(private config: ClarityConfig) { }
77

88
async format(entry: LogEntry): Promise<string> {
9-
const timestamp = this.formatTimestamp(entry.timestamp)
10-
const level = this.formatLevel(entry.level)
11-
const prefix = this.formatPrefix(entry.name)
12-
const message = this.formatMessage(entry.message)
13-
14-
return `${timestamp} ${prefix} ${level}: ${message}`
15-
}
16-
17-
private formatTimestamp(timestamp: Date): string {
18-
const time = `${timestamp.toLocaleTimeString()}:${timestamp.getMilliseconds()}`
19-
return this.useColors ? colors.gray(time) : time
20-
}
21-
22-
private formatLevel(level: string): string {
23-
if (!this.useColors)
24-
return level.toUpperCase()
9+
const timestamp = this.config.timestamp ? `${colors.gray(entry.timestamp.toISOString())} ` : ''
10+
const name = colors.gray(`[${entry.name}]`)
11+
12+
const levelSymbols: Record<LogLevel, string> = {
13+
debug: '🔍',
14+
info: 'ℹ️',
15+
success: '✅',
16+
warning: '⚠️',
17+
error: '❌',
18+
}
2519

26-
switch (level) {
27-
case 'debug': return colors.gray('DEBUG')
28-
case 'info': return colors.blue('INFO')
29-
case 'success': return colors.green('SUCCESS')
30-
case 'warning': return colors.yellow('WARNING')
31-
case 'error': return colors.red('ERROR')
32-
default: return level.toUpperCase()
20+
const levelColors: Record<LogLevel, (text: string) => string> = {
21+
debug: colors.gray,
22+
info: colors.blue,
23+
success: colors.green,
24+
warning: colors.yellow,
25+
error: colors.red,
3326
}
34-
}
3527

36-
private formatPrefix(name: string): string {
37-
const prefix = `[${name}]`
38-
return this.useColors ? colors.blue(prefix) : prefix
39-
}
28+
// Handle positional formatting if args are present
29+
let message = entry.message
30+
if (Array.isArray(entry.args))
31+
message = format(entry.message, ...entry.args)
32+
33+
const symbol = this.config.colors ? levelSymbols[entry.level] : ''
34+
message = this.config.colors
35+
? levelColors[entry.level](message)
36+
: message
4037

41-
private formatMessage(message: any): string {
42-
if (typeof message === 'string')
43-
return message
44-
return JSON.stringify(message, null, 2)
38+
return `${timestamp}${name} ${symbol} ${message}`
4539
}
4640
}

src/formatters/types.ts

-5
This file was deleted.

src/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export * from './colors'
2-
export * from './formatters'
3-
export * from './logger'
4-
export * from './storage/config-manager'
5-
export * from './storage/log-manager'
2+
export * from './config'
3+
export * from './format'
64
export * from './types'
75
export * from './utils'

0 commit comments

Comments
 (0)