Add logger dependency and replace console logging

- Import LoggerComponent from ior:gitea:gitea.metatrom.net:universal-components/logger@1.0.0
- Replace console.warn and console.info with appropriate logger methods
- Use warn level for fallback scenarios when native implementations fail
- Use info level for polyfill installation notifications

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Chris Daßler
2025-08-29 15:01:40 +02:00
parent 3342f7e40b
commit d77090d04a

View File

@@ -6,6 +6,7 @@
* @module text-encoding@1.0.0
*/
import { LoggerComponent } from 'ior:gitea:gitea.metatrom.net:universal-components/logger@1.0.0';
import { TextDecoderPolyfill } from './TextDecoderPolyfill';
import { TextEncoderPolyfill } from './TextEncoderPolyfill';
import type {
@@ -17,6 +18,7 @@ import type {
export class TextEncodingFactory implements ITextEncodingFactory {
private static instance: TextEncodingFactory;
private static logger = new LoggerComponent('TextEncodingFactory');
/**
* Get factory singleton instance
@@ -40,7 +42,7 @@ export class TextEncodingFactory implements ITextEncodingFactory {
return new TextEncoder();
} catch (e) {
// Fall back to polyfill if native fails
console.warn('[TextEncodingFactory] Native TextEncoder failed, using polyfill:', e);
TextEncodingFactory.logger.warn('Native TextEncoder failed, using polyfill:', e);
}
}
@@ -59,7 +61,7 @@ export class TextEncodingFactory implements ITextEncodingFactory {
return new TextDecoder(label, options);
} catch (e) {
// Fall back to polyfill if native fails
console.warn('[TextEncodingFactory] Native TextDecoder failed, using polyfill:', e);
TextEncodingFactory.logger.warn('Native TextDecoder failed, using polyfill:', e);
}
}
@@ -113,20 +115,22 @@ export function createTextDecoder(label?: string, options?: TextDecoderOptions):
* This makes TextEncoder/TextDecoder available everywhere
*/
export function installTextEncodingPolyfills(): void {
const logger = new LoggerComponent('TextEncodingPolyfills');
// @ts-expect-error
if (typeof global !== 'undefined') {
// @ts-expect-error
if (typeof global.TextEncoder === 'undefined') {
// @ts-expect-error
global.TextEncoder = TextEncoderPolyfill;
console.info('[TextEncodingFactory] Installed TextEncoder polyfill globally');
logger.info('Installed TextEncoder polyfill globally');
}
// @ts-expect-error
if (typeof global.TextDecoder === 'undefined') {
// @ts-expect-error
global.TextDecoder = TextDecoderPolyfill;
console.info('[TextEncodingFactory] Installed TextDecoder polyfill globally');
logger.info('Installed TextDecoder polyfill globally');
}
}
}