# Memorio Logger

> 🖥️ **Browser Only**: This feature is only available in browser console

Automatic logging middleware for tracking all state changes in Memorio.

## Overview

The logger automatically tracks all operations (set, delete, clear) across all modules:
- State
- Store
- Session
- Cache

## Configuration

### configure(options)

Configure the logger.

```javascript
memorio.logger.configure({
  enabled: true,           // Enable/disable logging
  logToConsole: true,     // Log to browser console
  customHandler: function(entry) { ... }, // Custom handler
  modules: ['state', 'store', 'session', 'cache'], // Modules to log
  maxEntries: 1000        // Maximum log history size
})
```

### enable()

Enable logging.

```javascript
memorio.logger.enable()
```

### disable()

Disable logging.

```javascript
memorio.logger.disable()
```

## Methods

### getHistory()

Get all log entries.

```javascript
const history = memorio.logger.getHistory()
// Returns array of LogEntry objects
```

### getStats()

Get statistics about logged operations.

```javascript
const stats = memorio.logger.getStats()
// Returns: { total, state, store, session, cache, set, get, delete, clear }
```

### clearHistory()

Clear log history.

```javascript
memorio.logger.clearHistory()
```

### exportLogs()

Export logs as JSON string.

```javascript
const json = memorio.logger.exportLogs()
```

## Log Entry Structure

```javascript
{
  timestamp: "2026-02-18T12:00:00.000Z",
  module: "state",
  action: "set",
  path: "user.name",
  value: "John",
  previousValue: "Jane"
}
```

## Examples

### Basic usage

```javascript
// Logging is enabled by default
state.user = { name: 'John' }
// Console: [Memorio:STATE] set user → value: { name: 'John' }
```

### Get statistics

```javascript
const stats = memorio.logger.getStats()
console.debug(stats)
// { total: 15, state: 5, store: 3, session: 2, cache: 5, set: 10, get: 0, delete: 3, clear: 2 }
```

### Disable specific modules

```javascript
memorio.logger.configure({
  modules: ['state'] // Only log state changes
})
```

### Custom handler

```javascript
memorio.logger.configure({
  customHandler: (entry) => {
    // Send to analytics
    analytics.track('memorio_change', entry)
  }
})
```

### Export and analyze

```javascript
// Get all logs
const logs = memorio.logger.getHistory()

// Filter by module
const stateLogs = logs.filter(l => l.module === 'state')

// Filter by action
const setOperations = logs.filter(l => l.action === 'set')

// Export for debugging
console.debug(memorio.logger.exportLogs())
```
