The ACL module is designed with extensibility in mind, allowing developers to tailor the logging behavior to their specific needs. Below are several common use cases for extending or customizing ACL:
You can add custom log levels (e.g., verbose
, critical
) by creating new methods in your subclass and setting custom colors for each level.
class CustomACL extends ACL {
verbose(condition = true, ...args) {
this.logWithColorAndCondition(this.color.info, condition, 0, ...args);
}
critical(condition = true, ...args) {
this.logWithColorAndCondition(this.color.fatal, condition, 5, ...args);
}
}
You can extend ACL to send logs to third-party services (e.g., Elasticsearch, Loggly, Datadog) by overriding the logWithColorAndCondition
method.
class ServiceLogger extends ACL {
logWithColorAndCondition(color, condition, level, ...args) {
super.logWithColorAndCondition(color, condition, level, ...args);
// Custom integration code to send logs to a third-party service
}
}
You can override methods like getFormattedMemoryUsage
, writeHeader
, or getCallerInfo
to adapt ACL to your logging needs.
Override writeHeader
to customize the log file header:
class CustomHeaderLogger extends ACL {
writeHeader() {
const customHeader = `Custom Log File - ${new Date().toISOString()}\n`;
fs.appendFileSync(this.outputFilename, customHeader, "utf8");
}
}
The ACL class includes a powerful utility to dynamically load methods and properties from external classes. Use loadDynamicMethodsAndProperties
to inject custom behaviors:
class ExtendedACL extends ACL {
constructor(config) {
super(config);
this.loadDynamicMethodsAndProperties(CustomMethodsClass);
}
}
By using loadDynamicMethodsAndProperties
, you can easily integrate custom methods without modifying the base class.