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.
- 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.
Install LogTrek via npm:
npm install logtrekimport { 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');const logger = new Logger('warn', 'file', { location: '/var/log/app.log' });
logger.warn('Warning: Disk space is low');
logger.error('Error: Disk write failed');const logger = new Logger('debug', 'console');
logger.debug('Debugging information');
logger.info('Operational message');
logger.error('Critical error occurred');-
Clone the repository:
git clone https://github.com/yourusername/logtrek.git cd logtrek -
Install dependencies:
npm install
-
Build the project:
npm run build
-
Run tests:
npm test
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 configuration
Plugins allow you to extend LogTrek's functionality. Follow these steps to create a custom 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;const logger = new Logger('info', 'custom');
logger.info('Using the custom plugin!');All features must have corresponding tests. This is a core philosophy of LogTrek to ensure reliability and maintainability.
npm testPlace 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');
});
});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');
});
});- 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.
- 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.
LogTrek is licensed under the MIT License.