A scalable, framework-agnostic logging system with built-in support for various frameworks
npm install loglog-coreA scalable, framework-agnostic logging system with built-in support for Express.js and Next.js, featuring environment-specific configurations for both client and server-side logging.
- Environment-specific configurations (development, staging, production)
- Client-side and server-side logging support
- Remote logging for client-side
- File rotation for server-side
- Framework-specific adapters (Express.js, Next.js)
- Structured logging with JSON support
- Sensitive data redaction
- OpenTelemetry integration
- Performance timing
- Colorized console output
Choose your preferred package manager:
``bashUsing npm
npm install loglog-core
For CLI usage, install globally:
`bash
Using npm
npm install -g loglog-coreUsing yarn
yarn global add loglog-coreUsing pnpm
pnpm add -g loglog-core
`CLI Commands
LogLog comes with a command-line interface that helps you manage and analyze your logs. Install globally to use the CLI:
`bash
npm install -g loglog-core
`Available commands:
`bash
Initialize LogLog configuration in your project
loglog initView real-time log stream with optional filtering
loglog tail [--level=] [--format=json|text] [--filter=]Search through log files
loglog search [--from=] [--to=] [--level=]Rotate log files manually
loglog rotateView log statistics and summaries
loglog stats [--from=] [--to=]Validate LogLog configuration
loglog validateClear log files (with confirmation)
loglog clear [--older-than=]
`$3
`bash
Watch INFO and above logs in real-time
loglog tail --level=infoSearch for error logs from last 24 hours
loglog search "error" --from="24h"View log statistics for the current month
loglog stats --from="1M"Rotate logs that are older than 7 days
loglog rotate --older-than=7Clear all logs older than 30 days
loglog clear --older-than=30
`Basic Usage
$3
`typescript
import { Logger, LogLevel } from 'loglog-core';const logger = new Logger({
environment: process.env.NODE_ENV || 'development',
serverConfig: {
enableConsole: true,
enableFile: true,
level: LogLevel.INFO,
logDir: 'logs'
}
});
logger.info('Server started', { port: 3000 });
logger.error('Error occurred', new Error('Something went wrong'));
`$3
`typescript
import { Logger, LogLevel } from 'loglog-core';const logger = new Logger({
environment: process.env.NODE_ENV || 'development',
clientConfig: {
enableConsole: true,
enableFile: false,
enableRemote: true,
remoteEndpoint: '/api/logs',
level: LogLevel.INFO,
structured: true,
colorize: true,
timestamp: true,
labels: {
app: 'my-client-app'
}
}
});
logger.info('Application initialized', { version: '1.0.0' });
`Framework Integration
For detailed framework-specific integration guides, please refer to:
- Express.js Integration Guide
- Next.js Integration Guide
Advanced Features
$3
`typescript
const logger = new Logger();// Add context that will be included in all subsequent logs
const userLogger = logger.withContext({ userId: '123' });
userLogger.info('Processing user'); // Includes userId in context
`$3
`typescript
const logger = new Logger();// Automatically time async operations
const result = await logger.time(
'Database query completed',
async () => await db.query('SELECT * FROM users'),
{ operation: 'user_query' }
);
`$3
`typescript
const logger = new Logger();// Clean up resources and flush pending logs
await logger.cleanup();
`Creating Custom Adapters
`typescript
import { LoggingAdapter, Logger, RequestInfo, ResponseInfo } from 'loglog-core';export class CustomAdapter implements LoggingAdapter {
initialize(logger: Logger): void {
// Initialize adapter
}
createRequestLogger(requestInfo: RequestInfo): Logger {
// Create request-specific logger
}
logRequest(logger: Logger, requestInfo: RequestInfo): void {
// Log request details
}
logResponse(logger: Logger, responseInfo: ResponseInfo): void {
// Log response details
}
}
``