logtrek
v0.3.0
Published
LogTrek is a modular logging library for Node.js and TypeScript, boldly going where no logs have gone before. Designed for speed, flexibility, and futuristic elegance, LogTrek provides a robust logging solution with plugin-based extensibility and customiz
Readme
LogTrek
LogTrek is a modular logging library for Node.js and TypeScript, boldly going where no logs have gone before. Designed for speed, flexibility, and futuristic elegance, LogTrek provides a robust logging solution with plugin-based extensibility and customizable log levels. Whether you're exploring new logging frontiers or managing critical system logs, LogTrek has you covered.
Features
- Modular Design: Easily extend functionality by creating custom plugins.
- Built-in Plugins: Supports console and file-based logging out of the box.
- Customizable Log Levels: Fine-tune which logs are displayed or written.
- TypeScript Support: Strongly typed for a seamless developer experience.
- Test-First Philosophy: All features are required to have corresponding tests.
Installation
Install LogTrek via npm:
npm install logtrekUsage
Basic Example
import { Logger } from 'logtrek';
const logger = new Logger('info', 'console');
logger.info('This is an informational message');
logger.warn('This is a warning');
logger.error('This is an error message');File-Based Logging
const logger = new Logger('warn', 'file', { location: '/var/log/app.log' });
logger.warn('Warning: Disk space is low');
logger.error('Error: Disk write failed');Custom Log Levels
const logger = new Logger('debug', 'console');
logger.debug('Debugging information');
logger.info('Operational message');
logger.error('Critical error occurred');Development
Getting Started
Clone the repository:
git clone https://github.com/yourusername/logtrek.git cd logtrekInstall dependencies:
npm installBuild the project:
npm run buildRun tests:
npm test
Project Structure
logtrek/
├── src/ # Source code
│ ├── logger.ts # Core Logger implementation
│ ├── pluginLoader.ts # Plugin loader
│ ├── plugins/ # Built-in plugins (console, file)
├── tests/ # Test cases
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
├── dist/ # Compiled output
├── README.md # Project documentation
├── package.json # Project metadata
└── tsconfig.json # TypeScript configurationCreating a New Plugin
Plugins allow you to extend LogTrek's functionality. Follow these steps to create a custom plugin:
1. Define Your Plugin
Create a new file in the src/plugins/ directory:
import { LoggerPlugin, LogLevel } from '../types';
const customPlugin: LoggerPlugin = {
pluginType: 'custom',
configure: (options: Record<string, any>) => {
console.log('Custom plugin configured with options:', options);
},
write: (level: LogLevel, message: string, meta?: Record<string, any>) => {
console.log(`[${level.toUpperCase()}]: ${message}`, meta);
},
};
export default customPlugin;2. Use the Plugin
const logger = new Logger('info', 'custom');
logger.info('Using the custom plugin!');Writing Tests
All features must have corresponding tests. This is a core philosophy of LogTrek to ensure reliability and maintainability.
Running Tests
npm testWriting Unit Tests
Place your unit tests in the tests/unit/ directory. Example:
import { Logger } from '../../src/logger';
describe('Logger', () => {
it('should log messages at the correct level', () => {
const logger = new Logger('info', 'console');
logger.info('This is a test');
});
});Writing Integration Tests
Place integration tests in the tests/integration/ directory. Example:
import { Logger } from '../../src/logger';
describe('Integration Test', () => {
it('should log to the console and file', () => {
const logger = new Logger('warn', 'file', { location: 'test.log' });
logger.warn('Integration test message');
});
});Contributing
Guidelines
- Test Coverage: Every new feature must have corresponding tests. No feature is complete without tests.
- Code Style: Follow the existing code style and conventions.
- Pull Requests: Include a description of your changes and why they are necessary.
Development Workflow
- Create a new branch:
git checkout -b feature/my-new-feature - Make your changes and write tests.
- Run tests to ensure everything works:
npm test - Commit your changes:
git commit -m "Add my new feature" - Push your branch:
git push origin feature/my-new-feature - Open a pull request on GitHub.
License
LogTrek is licensed under the MIT License.
