Constructor
# new LoggedClass()
This class supplies inheriting classes with a lazily created, context-aware Logger via the protected log getter. This promotes consistent, structured logging without the need for manual wiring.
A base class that provides a ready-to-use logger instance.
sequenceDiagram
participant Client
participant Instance as Subclass Instance
participant Getter as LoggedClass.log
participant Logging as Logging
participant Logger as Logger
Client->>Instance: call someMethod()
Instance->>Getter: access this.log
Getter->>Logging: Logging.for(this)
Logging-->>Getter: return Logger
Getter-->>Instance: return Logger
Instance->>Logger: info/debug/error(...)
Example
class UserService extends LoggedClass {
create(user: User) {
this.log.info(`Creating user ${user.id}`);
}
}
const svc = new UserService();
svc.create({ id: "42" });
Members
# log
This method calls Logging.for with the subclass instance to obtain a logger whose context matches the subclass name.
Lazily provides a context-aware logger for the current instance.
Methods
# protected log() → {Logger}
This method calls Logging.for with the subclass instance to obtain a logger whose context matches the subclass name.
Lazily provides a context-aware logger for the current instance.
A logger that is bound to the subclass context.