Skip to content

Commit ba8a7f4

Browse files
committed
chore: add integration tests
chore: wip chore: wip chore: wip
1 parent 78fa994 commit ba8a7f4

File tree

4 files changed

+1704
-175
lines changed

4 files changed

+1704
-175
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.DS_Store
33
.idea
44
*.log
5+
*.gz
56
*.tgz
67
coverage
78
dist

src/formatters/pretty.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Formatter, LogEntry } from '../types'
2+
import process from 'node:process'
3+
import { isServerProcess } from '../utils'
4+
5+
export class PrettyFormatter implements Formatter {
6+
async format(entry: LogEntry): Promise<string> {
7+
const isServer = await isServerProcess()
8+
const metadata = await this.getMetadata(isServer)
9+
10+
return `[${entry.timestamp.toISOString()}] ${entry.level} ${entry.name}: ${entry.message}\n${JSON.stringify(metadata)}`
11+
}
12+
13+
private async getMetadata(isServer: boolean) {
14+
if (isServer) {
15+
const { hostname } = await import('node:os')
16+
return {
17+
pid: process.pid,
18+
hostname: hostname(),
19+
environment: process.env.NODE_ENV || 'development',
20+
platform: process.platform,
21+
version: process.version,
22+
}
23+
}
24+
25+
return {
26+
userAgent: navigator.userAgent,
27+
hostname: window.location.hostname || 'browser',
28+
environment: process.env.NODE_ENV || process.env.BUN_ENV || 'development',
29+
viewport: {
30+
width: window.innerWidth,
31+
height: window.innerHeight,
32+
},
33+
language: navigator.language,
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)