Kind: Class
Source: packages/testing/services/testing-logger.service.ts
Part of: Testing
TestingLogger is a test-focused logger implementation that provides the standard logging methods used throughout the application: log, warn, debug, verbose, and error. It allows tests to capture, inspect, or safely handle log output without depending on the production logging infrastructure.
Extends: ConsoleLogger
Methods
| Method | Signature | Returns |
|---|---|---|
log | log(message: string) | void |
warn | warn(message: string) | void |
debug | debug(message: string) | void |
verbose | verbose(message: string) | void |
error | error(message: string, optionalParams: any[]) | void |
Diagram
mermaidgraph LR Test[Test Suite] --> Logger[TestingLogger] Logger --> Log[log()] Logger --> Warn[warn()] Logger --> Debug[debug()] Logger --> Verbose[verbose()] Logger --> Error[error()] Log --> Assertions[Test Assertions] Warn --> Assertions Debug --> Assertions Verbose --> Assertions Error --> Assertions
Usage
tsimport { TestingLogger } from '@your-package/testing';
describe('ExampleService', () => {
it('logs an expected message', () => {
const logger = new TestingLogger();
logger.log('Processing started');
logger.warn('Optional configuration is missing');
logger.debug('Request payload received');
logger.verbose('Additional diagnostic details');
logger.error('Processing failed');
// Use the testing logger with the service under test.
// const service = new ExampleService(logger);
});
});
AI Coding Instructions
- Use
TestingLoggerwhen unit or integration tests need a logger dependency instead of the production logger. - Call the method that matches the intended log level:
logfor normal messages,warnfor recoverable issues, anderrorfor failures. - Keep test logging deterministic; avoid relying on timestamps, environment-specific values, or external output destinations.
- When adding logger-compatible services, preserve support for all standard methods exposed by
TestingLogger. - Prefer assertions against expected logging behavior when logs represent important operational or error-handling outcomes.
How it works
TestingLogger
TestingLogger is a public class that extends Nest’s ConsoleLogger. Its constructor initializes the inherited logger with the context string "Testing". [packages/testing/services/testing-logger.service.ts:3-9]
Relationships
- IMPORTS →
ConsoleLogger
Was this page helpful?