Skip to content

Commit 38f7924

Browse files
committed
refactor(useLogger): add fallbacks, implement in useTokens, make flexible
1 parent 2a71d9a commit 38f7924

File tree

13 files changed

+155
-467
lines changed

13 files changed

+155
-467
lines changed

packages/0/src/composables/useLogger/README.md

Lines changed: 0 additions & 281 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Types
2+
import type { LoggerAdapter } from './adapter'
3+
4+
export class ConsolaLoggerAdapter implements LoggerAdapter {
5+
private consola: any
6+
7+
constructor (consolaInstance: any) {
8+
if (!consolaInstance) {
9+
throw new Error('Consola instance is required for ConsolaLoggerAdapter')
10+
}
11+
this.consola = consolaInstance
12+
}
13+
14+
debug (message: string, ...args: unknown[]) {
15+
this.consola.debug(message, ...args)
16+
}
17+
18+
info (message: string, ...args: unknown[]) {
19+
this.consola.info(message, ...args)
20+
}
21+
22+
warn (message: string, ...args: unknown[]) {
23+
this.consola.warn(message, ...args)
24+
}
25+
26+
error (message: string, ...args: unknown[]) {
27+
this.consola.error(message, ...args)
28+
}
29+
30+
trace (message: string, ...args: unknown[]) {
31+
if (this.consola.trace) {
32+
this.consola.trace(message, ...args)
33+
} else {
34+
this.consola.debug(message, ...args)
35+
}
36+
}
37+
38+
fatal (message: string, ...args: unknown[]) {
39+
if (this.consola.fatal) {
40+
this.consola.fatal(message, ...args)
41+
} else {
42+
this.consola.error('[FATAL]', message, ...args)
43+
}
44+
}
45+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export type { LoggerAdapter } from './adapter'
22

3-
export { Log4jsLoggerAdapter } from './log4js'
3+
export { ConsolaLoggerAdapter } from './consola'
44
export { PinoLoggerAdapter } from './pino'
55
export { Vuetify0LoggerAdapter } from './v0'
6-
export { WinstonLoggerAdapter } from './winston'

packages/0/src/composables/useLogger/adapters/log4js.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/0/src/composables/useLogger/adapters/v0.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ export class Vuetify0LoggerAdapter implements LoggerAdapter {
5353

5454
private format (level: LogLevel, message: string, ...args: unknown[]): [string, ...unknown[]] {
5555
const timestamp = this.timestamps ? this.timestamp() : ''
56-
const levelTag = `[${level.toUpperCase()}]`
57-
const prefixTag = `[${this.prefix}]`
56+
const prefixTag = `[${this.prefix} ${level.toLowerCase()}]`
5857

59-
const formattedMessage = [timestamp, prefixTag, levelTag, message]
58+
const formattedMessage = [timestamp, prefixTag, message]
6059
.filter(Boolean)
6160
.join(' ')
6261

0 commit comments

Comments
 (0)