File tree 4 files changed +1704
-175
lines changed
4 files changed +1704
-175
lines changed Original file line number Diff line number Diff line change 2
2
.DS_Store
3
3
.idea
4
4
* .log
5
+ * .gz
5
6
* .tgz
6
7
coverage
7
8
dist
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments