Core logging interfaces and types for the Bernier LLC logging ecosystem
npm install @bernierllc/logging-coreCore logging interfaces and types for the Bernier LLC logging ecosystem. This package provides the foundational types, interfaces, and utilities that other logging packages can build upon.
- Core Types: Log levels, entry types, and configuration interfaces
- Logger Interfaces: Base logger, audit logger, and system logger interfaces
- Transport Interfaces: Console, file, HTTP, and database transport definitions
- Environment Detection: Utilities for detecting and configuring based on environment
- Type Safety: Full TypeScript support with comprehensive type definitions
- Zero Dependencies: Pure TypeScript with no external dependencies
``bash`
npm install @bernierllc/logging-core
`typescript
import { LogLevel, LogEntry, AuditLogEntry, SystemLogEntry } from '@bernierllc/logging-core';
// Log levels
const level: LogLevel = 'info';
// Base log entry
const entry: LogEntry = {
level: 'info',
message: 'Application started',
timestamp: new Date().toISOString(),
metadata: { userId: 'user123' }
};
// Audit log entry
const auditEntry: AuditLogEntry = {
actorId: 'user123',
action: 'LOGIN',
target: 'auth-system',
ip: '192.168.1.100'
};
// System log entry
const systemEntry: SystemLogEntry = {
level: 'error',
message: 'Database connection failed',
error: new Error('Connection timeout'),
timestamp: new Date().toISOString()
};
`
`typescript
import { ILogger, IAuditLogger, ISystemLogger } from '@bernierllc/logging-core';
// Base logger interface
const logger: ILogger = {
log: (level, message, metadata) => { / implementation / },
error: (message, error, metadata) => { / implementation / },
warn: (message, metadata) => { / implementation / },
info: (message, metadata) => { / implementation / },
debug: (message, metadata) => { / implementation / }
};
// Audit logger interface
const auditLogger: IAuditLogger = {
...logger,
logAudit: (entry) => { / implementation / }
};
// System logger interface
const systemLogger: ISystemLogger = {
...logger,
logSystem: (entry) => { / implementation / }
};
`
`typescript
import { EnvironmentDetector } from '@bernierllc/logging-core';
// Get current environment
const env = EnvironmentDetector.getEnvironment(); // 'development' | 'staging' | 'production' | 'test'
// Environment checks
if (EnvironmentDetector.isProduction()) {
// Production-specific logic
}
if (EnvironmentDetector.isDevelopment()) {
// Development-specific logic
}
// Get environment defaults
const defaults = EnvironmentDetector.getEnvironmentDefaults();
`
`typescript
import { ITransport, ConsoleTransportConfig, FileTransportConfig } from '@bernierllc/logging-core';
// Transport interface
const transport: ITransport = {
name: 'console',
level: 'info',
log: async (entry) => { / implementation / },
close: async () => { / implementation / }
};
// Transport configurations
const consoleConfig: ConsoleTransportConfig = {
level: 'debug',
enableColors: true,
enableTimestamps: true
};
const fileConfig: FileTransportConfig = {
level: 'info',
filePath: './logs/app.log',
enableRotation: true,
maxSize: '10m',
maxFiles: '5'
};
`
#### LogLevel`typescript`
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
#### LogEntry`typescript`
interface LogEntry {
level: LogLevel;
message: string;
timestamp: string;
metadata?: Record
context?: string;
requestId?: string;
userId?: string;
}
#### AuditLogEntry`typescript`
interface AuditLogEntry {
actorId: string;
action: string;
target: string;
ip?: string;
metadata?: Record
timestamp?: string;
userId?: string;
sessionId?: string;
userAgent?: string;
requestId?: string;
}
#### SystemLogEntry`typescript`
interface SystemLogEntry extends LogEntry {
error?: Error;
}
#### ILogger
Base logger interface with standard logging methods.
#### IAuditLoggerILogger
Extends with audit-specific logging capabilities.
#### ISystemLoggerILogger
Extends with system logging capabilities.
#### ITransport
Interface for different logging destinations (console, file, HTTP, etc.).
#### EnvironmentDetector
Static class for environment detection and configuration.
This package serves as the foundation for the logging ecosystem:
`
@bernierllc/logging-core (this package)
├── Types and interfaces
├── Environment detection
└── Transport definitions
@bernierllc/logging (service package)
├── Winston integration
├── File logging with rotation
└── Production-ready defaults
@bernierllc/logging-utils (util package)
├── Performance monitoring
├── Log analysis tools
└── Format converters
``
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request
MIT License - see LICENSE file for details.