Skip to content

Commit 54da4b5

Browse files
committed
feat: update useLogger options
1 parent 1a28e89 commit 54da4b5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/core/src/composables/useLogger.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { OutputChannel } from 'vscode'
12
import { useOutputChannel } from '../composables/useOutputChannel'
23

3-
function defaultGetPrefix(type: string) {
4+
export function getDefaultLoggerPrefix(type: string) {
45
const date = new Date()
56
const year = String(date.getFullYear()).padStart(4, '0')
67
const month = String(date.getMonth() + 1).padStart(2, '0')
@@ -12,16 +13,21 @@ function defaultGetPrefix(type: string) {
1213
return `${year}-${month}-${day} ${hour}:${minute}:${second}.${millisecond} [${type}] `
1314
}
1415

16+
export interface UseLoggerOptions {
17+
outputChannel?: OutputChannel
18+
getPrefix?: ((type: string) => string) | null
19+
}
20+
1521
/**
1622
* Creates a logger that writes to the output channel.
1723
*
1824
* @category view
1925
*/
20-
export function useLogger(name: string, getPrefix = defaultGetPrefix) {
21-
const outputChannel = useOutputChannel(name)
26+
export function useLogger(name: string, options: UseLoggerOptions = {}) {
27+
const outputChannel = options.outputChannel ?? useOutputChannel(name)
2228

2329
const createLoggerFunc = (type: string) => (...message: any[]) => {
24-
outputChannel.appendLine(getPrefix(type) + message.join(' '))
30+
outputChannel.appendLine((options.getPrefix?.(type) ?? '') + message.join(' '))
2531
}
2632

2733
return {

0 commit comments

Comments
 (0)