-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
70 lines (51 loc) · 2.65 KB
/
Copy pathdemo.ts
File metadata and controls
70 lines (51 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {createFiro, type Firo, FIRO_COLORS} from './src'
const mainWithColors = (log: Firo) => {
// 1. Start with a clean system message
log.info('firo 🌲 initialized', {version: '0.1.0', mode: 'dev'})
// 2. Global context (different colors for keys)
log.addContext('service', 'auth-api')
log.addContext('region', {value: 'west', color: '38;5;214'}) // 256-color orange
log.addContext('worker', {value: 'primary', color: FIRO_COLORS.pink}) // named color pink
log.addContext('color2', {value: 'lilac', color: FIRO_COLORS.lilac, omitKey: true}) // named color lilac
log.addContext('color3', {value: 'pistachio', color: FIRO_COLORS.green, omitKey: true}) // named color pistachio
// 3. Dimmed debug (visual hierarchy)
log.debug('Reading configuration...', {source: 'env', items: 12})
// 4. Child logger with request-specific context
const reqLog = log.child({reqId: 'a7b8', user: 'firo'})
// 5. Callable shorthand (log() instead of log.info())
reqLog('Processing incoming request', {method: 'POST', path: '/v1/upload'})
// 6. Vibrant Warning
reqLog.warn('Heavy payload detected', {size: '4.2MB', limit: '5.0MB'})
// 7. Sharp Error with stack trace
const error = new Error('Disk quota exceeded')
reqLog.error('File upload failed', error)
// 8. Closing log
log.info('Service remains healthy')
}
const main = (log: Firo) => {
// 1. Start with a clean system message
log.info('firo 🌲 initialized', {version: '0.1.0', mode: 'dev'})
// 2. Global context (different colors for keys)
log.addContext('service', 'auth')
// log.addContext('region', 'west')
// log.addContext('worker', 'primary', {color: FIRO_COLORS.pink}) // truecolor
// 3. Dimmed debug (visual hierarchy)
log.debug('Reading configuration...', {source: 'env', items: 12})
// 4. Child logger with request-specific context
const reqLog = log.child({reqId: 'a7b8', user: {value: 'firo'}})
// 5. Callable shorthand (log() instead of log.info())
reqLog('Processing incoming request', {method: 'POST', path: '/v1/upload'})
reqLog('User resolved (expanded output)', {user: {id: 123, name: 'Firo'}}, {pretty: true})
// 6. Vibrant Warning
reqLog.warn('Heavy payload detected', {size: '4.2MB', limit: '5.0MB'})
// 7. Sharp Error with stack trace
const error = new Error('Disk quota exceeded')
reqLog.error('File upload failed', error)
// 8. Closing log
log.info('Service remains healthy')
}
console.log('Beautiful colors in dev mode:\n')
main(createFiro())
console.log('\nAnd robust and boring NDJSON in production mode:\n')
main(createFiro({mode: 'prod'}))
console.log('\n')