Constructor
new AvenxLogger(configopt)
Creates an instance of AvenxLogger.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
config |
object |
<optional> |
Application logger configuration options. |
- Source:
Examples
// 1. Basic initialization during application setup:
const app = new AvenxApp({
logging: {
level: 'debug',
silent: false
}
});
// 2. Usage inside component methods:
// Import the shared logger from the runtime entry point — component
// instances do not expose `this.logger`.
import { logger } from 'avenx-core/runtime';
export default {
name: 'TargetSyncComponent',
methods: {
async syncDatabase(targets) {
logger.info('Starting celestial synchronization...', { count: targets.length });
try {
if (!targets || targets.length === 0) {
logger.warn('Sync skipped: list is empty.');
return;
}
logger.debug('Processing batch.', { sampleId: targets[0].id });
} catch (error) {
logger.error('Database sync failed.', { error: error.message });
}
}
}
};
// 3. Registering a Custom Formatter:
const customFormatter = (level, args) => {
return [`[MY-APP] [${level.toUpperCase()}]:`, ...args];
};
const loggerWithFormatter = new AvenxLogger({ formatter: customFormatter });
// 4. Registering a Custom Transport:
const fileTransport = {
log(level, formattedArgs, rawArgs) {
// Append custom streaming/file logic here
fs.appendFileSync('./app.log', formattedArgs.join(' ') + '\n');
}
};
const loggerWithTransport = new AvenxLogger({ transports: [fileTransport] });
Classes
Methods
child(bindingsopt) → {AvenxLogger}
Creates a child logger instance that inherits the parent's log level, transports, and formatter. Supports a string shorthand for prefix-only binding, or an object with prefix and/or componentName. Parent bindings are merged with the new bindings (child overrides parent on conflict).
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bindings |
string | object |
<optional> |
Bindings configuration for the child logger. Properties
|
- Source:
Returns:
A new logger instance with inherited configuration and merged bindings.
- Type
- AvenxLogger
Examples
// String shorthand
const authLogger = logger.child('[AuthBridge]');
authLogger.info('User logged in');
// Output: [AuthBridge] [Avenx info] User logged in
// Object bindings with context
const dbLogger = logger.child({ prefix: '[DB]', componentName: 'DatabaseBridge' });
dbLogger.warn('Connection slow');
// Output: [DB] [Avenx warn] [DatabaseBridge] Connection slow
// Nested child loggers
const child = logger.child('[Parent]').child('[Child]');
configure(config)
Configures the logger instance options.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
object | Configuration options. |
- Source:
debug(…args)
Logs a message with debug level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
error(…args)
Logs a message with error level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
fatal(…args)
Logs a message with fatal level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
info(…args)
Logs a message with info level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
log(…args)
Alias for info level logging.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
setLevel(level)
Sets the minimum log severity level programmatically.
Parameters:
| Name | Type | Description |
|---|---|---|
level |
string | Log level name ('trace', 'debug', 'info', 'warn', 'error', 'fatal', 'off', 'silent'). |
- Source:
shouldLog(level) → {boolean}
Helper to check if a specific level should be logged.
Parameters:
| Name | Type | Description |
|---|---|---|
level |
string | Log level to test. |
- Source:
Returns:
True if logger should log the given level.
- Type
- boolean
trace(…args)
Logs a message with trace level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
warn(…args)
Logs a message with warn level.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Arguments to log. |
- Source:
write(level, …args)
Writes the log statement through configured formatter and transports.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
level |
string | Log level name. |
|
args |
any |
<repeatable> |
Arguments to log. |
- Source: