Logger: improving the logger, and using it in client code.
This commit is contained in:
@ -6,6 +6,7 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
import type { InitConverseJSParams, ChatPeertubeIncludeMode } from 'shared/lib/types'
|
||||
import { computeAutoColors } from './colors'
|
||||
import { getBaseRoute } from './uri'
|
||||
import { logger } from './logger'
|
||||
|
||||
// FIXME: better declaration (see builtin.ts)
|
||||
declare global {
|
||||
@ -143,7 +144,7 @@ async function displayConverseJS (
|
||||
if (!a) { return }
|
||||
if (a.getAttribute('href') !== '#') { return }
|
||||
|
||||
console.log('[peertube-plugin-livechat] intercepting a click on href=# in converse root, canceling the event.')
|
||||
logger.log('Intercepting a click on href=# in converse root, canceling the event.')
|
||||
ev.preventDefault()
|
||||
})
|
||||
|
||||
|
@ -3,19 +3,27 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
interface Logger {
|
||||
log: (s: string) => void
|
||||
info: (s: string) => void
|
||||
error: (s: string) => void
|
||||
warn: (s: string) => void
|
||||
log: (s: any) => void
|
||||
info: (s: any) => void
|
||||
error: (s: any) => void
|
||||
warn: (s: any) => void
|
||||
createLogger: (p: string) => Logger
|
||||
}
|
||||
|
||||
function createLogger (prefix: string): Logger {
|
||||
return {
|
||||
log: (s: string) => console.log('[' + prefix + '] ' + s),
|
||||
info: (s: string) => console.info('[' + prefix + '] ' + s),
|
||||
error: (s: string) => console.error('[' + prefix + '] ' + s),
|
||||
warn: (s: string) => console.warn('[' + prefix + '] ' + s),
|
||||
log: (s: any) => {
|
||||
typeof s === 'string' ? console.log('[' + prefix + '] ' + s) : console.log('[' + prefix + ']', s)
|
||||
},
|
||||
info: (s: any) => {
|
||||
typeof s === 'string' ? console.info('[' + prefix + '] ' + s) : console.info('[' + prefix + ']', s)
|
||||
},
|
||||
error: (s: any) => {
|
||||
typeof s === 'string' ? console.error('[' + prefix + '] ' + s) : console.error('[' + prefix + ']', s)
|
||||
},
|
||||
warn: (s: any) => {
|
||||
typeof s === 'string' ? console.warn('[' + prefix + '] ' + s) : console.warn('[' + prefix + ']', s)
|
||||
},
|
||||
createLogger: (p: string) => createLogger('peertube-plugin-livechat>' + p)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user