From d42bcf01a7dcb04ef815b0f5ee74149118754f8b Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 14 Jun 2024 14:48:27 +0200 Subject: [PATCH] Logger: * new createLogger function * custom elements have their own logger --- .../common/videowatch/elements/share-chat.ts | 5 ++++ client/utils/logger.ts | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client/common/videowatch/elements/share-chat.ts b/client/common/videowatch/elements/share-chat.ts index 49568a5c..a53eee5e 100644 --- a/client/common/videowatch/elements/share-chat.ts +++ b/client/common/videowatch/elements/share-chat.ts @@ -101,6 +101,11 @@ export class ShareChatElement extends LivechatElement { this._restorePreviousState() } + protected override updated (changedProperties: PropertyValues): void { + super.updated(changedProperties) + this.logger.info('Update!') + } + protected override render = (): TemplateResult => { return html` ${tplShareChatTabs(this)} diff --git a/client/utils/logger.ts b/client/utils/logger.ts index 6e30cb83..de65457b 100644 --- a/client/utils/logger.ts +++ b/client/utils/logger.ts @@ -2,13 +2,26 @@ // // SPDX-License-Identifier: AGPL-3.0-only -const logger = { - log: (s: string) => console.log('[peertube-plugin-livechat] ' + s), - info: (s: string) => console.info('[peertube-plugin-livechat] ' + s), - error: (s: string) => console.error('[peertube-plugin-livechat] ' + s), - warn: (s: string) => console.warn('[peertube-plugin-livechat] ' + s) +interface Logger { + log: (s: string) => void + info: (s: string) => void + error: (s: string) => void + warn: (s: string) => 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), + createLogger: (p: string) => createLogger('peertube-plugin-livechat>' + p) + } +} + +const logger = createLogger('peertube-plugin-livechat') + export { logger }