@bernierllc/logging-core
v0.3.0
Published
Core logging interfaces and types for the Bernier LLC logging ecosystem
Readme
@bernierllc/logging-core
Core 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.
Features
- 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
Installation
npm install @bernierllc/logging-coreUsage
Basic Types
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()
};Logger Interfaces
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 */ }
};Environment Detection
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();Transport Interfaces
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'
};API Reference
Types
LogLevel
type LogLevel = 'error' | 'warn' | 'info' | 'debug';LogEntry
interface LogEntry {
level: LogLevel;
message: string;
timestamp: string;
metadata?: Record<string, unknown>;
context?: string;
requestId?: string;
userId?: string;
}AuditLogEntry
interface AuditLogEntry {
actorId: string;
action: string;
target: string;
ip?: string;
metadata?: Record<string, unknown>;
timestamp?: string;
userId?: string;
sessionId?: string;
userAgent?: string;
requestId?: string;
}SystemLogEntry
interface SystemLogEntry extends LogEntry {
error?: Error;
}Interfaces
ILogger
Base logger interface with standard logging methods.
IAuditLogger
Extends ILogger with audit-specific logging capabilities.
ISystemLogger
Extends ILogger with system logging capabilities.
ITransport
Interface for different logging destinations (console, file, HTTP, etc.).
Utilities
EnvironmentDetector
Static class for environment detection and configuration.
Architecture
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 convertersContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details.
