
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@eclipse-emfcloud/model-logger
Advanced tools
This module provides a flexible logging factory that allows both default console logging and custom logging implementations.
The logger outputs messages to the console by default. To use the logger, import the getLogger function and create a logger instance with an optional name:
import { getLogger } from '@eclipse-emfcloud/model-logger';
export class AddressBook {
// Retrieve the logger
logger = getLogger('AddressBook');
addAddress = (newAddress: Address): boolean => {
const addresses = this.getAddressBook();
if (!addresses.find((address) => compareAddresses(address, newAddress))) {
logger.debug('Adding a new address');
// [AddressBook]: Adding a new address
addresses.push(newAddress);
return true;
} else {
logger.error('Trying to add an existing address');
// [AddressBook]: Trying to add an existing address
}
return false;
};
}
The logger supports five log levels similar to the standard Console interface methods: log, error, debug, warn and info.
You can override the default logging behavior to implement custom logging strategies, such as logging to both console and file system.
To customize the logger, override the LOGGER_FACTORY.getLogger method with your implementation:
// index.ts
import * as fs from 'fs';
import path from 'path';
import { LOGGER_FACTORY } from '@eclipse-emfcloud/model-logger';
const logFilePath = path.resolve(__dirname, 'logs.txt');
// User-specific logger
LOGGER_FACTORY.getLogger = (name?: string) => ({
error: (...messages: unknown[]) => {
console.error(name ? `${name}:` : '', ...messages);
fs.appendFileSync(
logFilePath,
`[error${name ? ` - ${name}:` : ''}]: ${messages.join(' ')}\n`
);
},
warn: (...messages: unknown[]) => {
console.warn(name ? `${name}:` : '', ...messages);
fs.appendFileSync(
logFilePath,
`[warn${name ? ` - ${name}:` : ''}]: ${messages.join(' ')}\n`
);
},
info: (...messages: unknown[]) => {
console.info(name ? `${name}:` : '', ...messages);
fs.appendFileSync(
logFilePath,
`[info${name ? ` - ${name}:` : ''}]: ${messages.join(' ')}\n`
);
},
log: (...messages: unknown[]) => {
console.log(name ? `${name}:` : '', ...messages);
fs.appendFileSync(
logFilePath,
`[log${name ? ` - ${name}:` : ''}]: ${messages.join(' ')}\n`
);
},
debug: (...messages: unknown[]) => {
console.debug(name ? `${name}:` : '', ...messages);
fs.appendFileSync(
logFilePath,
`[debug${name ? ` - ${name}:` : ''}]: ${messages.join(' ')}\n`
);
},
});
After overriding the factory, all subsequent calls to getLogger() will return your custom implementation while maintaining the named logger functionality.
FAQs
Logger for ModelManager
We found that @eclipse-emfcloud/model-logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.