@ooneex/logger component is a multi-backend logging layer. Every logger implements the same ILogger interface — init, error, warn, info, debug, log, success — so you can write to the terminal in development and ship to a database in production without changing a single call site. Each method takes a message, an optional structured data object, and per-call display options, and error additionally accepts an IException to log its name, status, and stack trace.
Why this component
- One interface, many backends.
TerminalLoggerandDatabaseLoggerboth implementILogger— swap backends without touching callers. - Six log levels.
error,warn,info,debug,log, andsuccessmap to theELogLevelenum, each with its own color and symbol in the terminal. - Structured data. Pass a typed
dataobject alongside the message; backends serialize it for you. - Exception-aware.
error()accepts a string or anIExceptionand records its name, status, and structured stack trace. - Container-managed. Register a logger class with a decorator and resolve it from the container.
How it works
You pick (or implement) a backend and register it. Calls go through theILogger methods; the backend handles formatting, serialization, and transport.
| Method | Purpose |
|---|---|
init() | Set up the logger (open handles, configure transports). Returns void or Promise<void>. |
error(message, data?, options?) | Log an error. message may be a string or an IException. |
warn(message, data?, options?) | Log a warning. |
info(message, data?, options?) | Log informational output. |
debug(message, data?, options?) | Log debug detail. |
log(message, data?, options?) | Log a general message. |
success(message, data?, options?) | Log a success message. |
ELogLevel levels — ERROR, WARN, INFO, DEBUG, LOG, SUCCESS. The built-in backends differ in where logs go, not in how you call them:
| Backend | Destination | Best for |
|---|---|---|
TerminalLogger | stdout / stderr | Local development and CLI output |
DatabaseLogger | PostgreSQL via LogsRepository | Persisting application and request logs |
TerminalLogger accepts LoggerOptionsType per call — showArrow, showTimestamp, showLevel, and useSymbol — to control how each line is rendered. Error and ERROR-level lines go to stderr; everything else goes to stdout.
Environment variables
Only the production backends need configuration.TerminalLogger needs none.
| Variable | Backend | Required | Purpose |
|---|---|---|---|
LOGS_DATABASE_URL | DatabaseLogger | Yes | PostgreSQL connection string for the logs database. |
Decorator and usage
@decorator.logger()
Registers a logger class with the container. It accepts an optional scope (defaults to EContainerScope.Singleton). All built-in loggers are decorated, and you use it to register custom loggers that implement ILogger.
error() accepts a plain message or an IException — when given an exception it records the name, status, and stack trace automatically:
Exceptions
The component throwsLoggerException when a backend is misconfigured. It carries a machine-readable key, a human-readable message, a data object, and an InternalServerError status.
Best practices
- Pick the backend per environment.
TerminalLoggerfor local/dev andDatabaseLoggerfor production — the call sites stay identical. - Pass structured data, not interpolated strings. Keep the message stable and put variable detail in the
dataobject so logs stay searchable. - Match the level to the meaning. Reserve
errorfor failures,warnfor recoverable issues,successfor completed operations, anddebugfor diagnostics. - Log exceptions as exceptions. Pass the
IExceptiontoerror()rather than itsmessagestring so the name, status, and stack trace are captured. - Keep
dataserializable. Backends serialize values; avoid class instances, functions, and circular references. - Throw
LoggerExceptionwith a stablekey. In custom backends, keep keys constant and put variable detail indata.
CLI command
Scaffold a logger class and its test file with the generator. It writes the class undermodules/<module>/src/loggers/<Name>Logger.ts and installs @ooneex/logger if it is missing.
| Option | Description | Default |
|---|---|---|
--name | Logger class name. The Logger suffix is appended automatically. | Prompted if omitted |
--module | Target module the class is generated into. | shared |
--override | Overwrite an existing class without prompting. | false |
ILogger stub, ready for you to implement each level method:
Use with Claude and Codex
The generator ships a matchinglogger:create skill. It runs the scaffold and then guides your AI agent through completing the logger — implementing init, log, debug, info, success, warn, and error against a real transport and wiring up its dependencies. Initialize the skills once for your agent:
- Claude
- Codex
Prompt
logger:create --name=Payments --module=payments, then implements the ILogger methods against your chosen transport.