File tree 1 file changed +10
-4
lines changed
packages/core/src/composables
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change
1
+ import type { OutputChannel } from 'vscode'
1
2
import { useOutputChannel } from '../composables/useOutputChannel'
2
3
3
- function defaultGetPrefix ( type : string ) {
4
+ export function getDefaultLoggerPrefix ( type : string ) {
4
5
const date = new Date ( )
5
6
const year = String ( date . getFullYear ( ) ) . padStart ( 4 , '0' )
6
7
const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' )
@@ -12,16 +13,21 @@ function defaultGetPrefix(type: string) {
12
13
return `${ year } -${ month } -${ day } ${ hour } :${ minute } :${ second } .${ millisecond } [${ type } ] `
13
14
}
14
15
16
+ export interface UseLoggerOptions {
17
+ outputChannel ?: OutputChannel
18
+ getPrefix ?: ( ( type : string ) => string ) | null
19
+ }
20
+
15
21
/**
16
22
* Creates a logger that writes to the output channel.
17
23
*
18
24
* @category view
19
25
*/
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 )
22
28
23
29
const createLoggerFunc = ( type : string ) => ( ...message : any [ ] ) => {
24
- outputChannel . appendLine ( getPrefix ( type ) + message . join ( ' ' ) )
30
+ outputChannel . appendLine ( ( options . getPrefix ?. ( type ) ?? '' ) + message . join ( ' ' ) )
25
31
}
26
32
27
33
return {
You can’t perform that action at this time.
0 commit comments