Skip to content

Logger

The `Logger` class provides structured console logging with prefixes and grouping. All output is gated behind the `debug` config flag — when off, nothing is logged.

View as Markdown llms.txt
import { getLogger } from '@segmentify/integration';
const logger = getLogger();
logger.log('Something happened');
logger.info('Info message');
logger.warn('Warning');
logger.error('Error');

All output is prefixed with [Segmentify] by default.

Create scoped loggers for different parts of your code:

const eventsLogger = getLogger().withPrefix('Events');
eventsLogger.log('Event sent');
// Output: [Segmentify] [Events] Event sent

Each withPrefix call creates a new instance — scoped loggers don’t affect each other.

const logger = getLogger();
logger.group('Processing events');
logger.log('Event 1 sent');
logger.log('Event 2 sent');
logger.groupEnd();

Toggle debug mode or change the prefix without re-initializing:

import { updateLoggerConfig } from '@segmentify/integration';
updateLoggerConfig({ debug: false });
updateLoggerConfig({ debug: true, prefix: '[MyApp]' });
if (getLogger().isDebugEnabled()) {
getLogger().log('Detailed debug info', expensiveComputation());
}