UNPKG

@rs-r2d2/log4ts

Version:

A powerful, flexible logging library for TypeScript inspired by Apache Log4j, featuring colored output and emojis

39 lines (38 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const PatternLayout_1 = require("../PatternLayout"); const LogLevel_1 = require("../../core/LogLevel"); describe('PatternLayout', () => { let layout; let mockEvent; beforeEach(() => { layout = new PatternLayout_1.PatternLayout(); mockEvent = { message: 'Test message', level: LogLevel_1.LogLevel.INFO, timestamp: new Date('2025-04-17T12:00:00Z'), loggerName: 'TestLogger' }; }); test('should format message with default pattern', () => { const formatted = layout.format(mockEvent); expect(formatted).toContain('[2025-04-17T12:00:00.000Z]'); expect(formatted).toContain('[INFO]'); expect(formatted).toContain('TestLogger'); expect(formatted).toContain('Test message'); }); test('should include error stack trace when present', () => { const error = new Error('Test error'); const eventWithError = Object.assign(Object.assign({}, mockEvent), { error }); const formatted = layout.format(eventWithError); expect(formatted).toContain('Test error'); expect(formatted).toContain('Error:'); }); test('should use custom pattern', () => { layout = new PatternLayout_1.PatternLayout('%p: %m'); const formatted = layout.format(mockEvent); // Using includes instead of exact match due to color formatting expect(formatted).toContain('INFO:'); expect(formatted).toContain('Test message'); }); });