# 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.

## Usage

```typescript
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.

## Component Prefixes

Create scoped loggers for different parts of your code:

```typescript
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.

## Console Grouping

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

## Runtime Updates

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

```typescript
import { updateLoggerConfig } from '@segmentify/integration';

updateLoggerConfig({ debug: false });
updateLoggerConfig({ debug: true, prefix: '[MyApp]' });
```

## Checking Debug State

```typescript
if (getLogger().isDebugEnabled()) {
  getLogger().log('Detailed debug info', expensiveComputation());
}
```

## See Also

- [Configuration - `debug` option](/02-configuration)
