|
@@ -1,25 +1,81 @@
|
|
|
# @converse/log
|
|
|
|
|
|
-A helper module which lets you log messages to the console, with different log levels.
|
|
|
+[](https://www.npmjs.com/package/@converse/log)
|
|
|
+[](https://github.com/conversejs/converse.js/blob/master/LICENSE.txt)
|
|
|
|
|
|
-Use `log.setLogLevel` to set the log level. All messages with a log level equal
|
|
|
-to or higher than what's set, will be logged to the console.
|
|
|
+A lightweight logging utility for Converse.js and related projects, providing configurable log levels and console output formatting.
|
|
|
+
|
|
|
+## Features
|
|
|
+
|
|
|
+- Multiple log levels (debug, info, warn, error, fatal)
|
|
|
+- Customizable output styling
|
|
|
+- Simple API
|
|
|
+- Zero dependencies
|
|
|
+- TypeScript support
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
```bash
|
|
|
npm install @converse/log
|
|
|
+# or
|
|
|
+yarn add @converse/log
|
|
|
```
|
|
|
|
|
|
-## Usage
|
|
|
+## Basic Usage
|
|
|
|
|
|
```javascript
|
|
|
import log from '@converse/log';
|
|
|
|
|
|
-log.setLogLevel('warn');
|
|
|
-log.debug('Debug message'); // This message will NOT be logged
|
|
|
-log.info('Info message'); // This message will NOT be logged
|
|
|
-log.warn('Warning message'); // This message will be logged
|
|
|
-log.error('Error message'); // This message will be logged
|
|
|
-log.fatal('Fatal error'); // This message will be logged
|
|
|
+// Configure log level (default: 'info')
|
|
|
+log.setLogLevel('debug');
|
|
|
+
|
|
|
+// Log messages
|
|
|
+log.debug('Detailed debug information');
|
|
|
+log.info('System status update');
|
|
|
+log.warn('Potential issue detected');
|
|
|
+log.error('Operation failed');
|
|
|
+log.fatal('Critical system failure');
|
|
|
+
|
|
|
+// Log with custom styling
|
|
|
+log.info('Important notice', 'color: blue; font-weight: bold');
|
|
|
+```
|
|
|
+
|
|
|
+## API Reference
|
|
|
+
|
|
|
+### `setLogLevel(level: string): void`
|
|
|
+Sets the minimum log level to display. Available levels (in order of severity):
|
|
|
+- `debug`
|
|
|
+- `info` (default)
|
|
|
+- `warn`
|
|
|
+- `error`
|
|
|
+- `fatal`
|
|
|
+
|
|
|
+### Logging Methods
|
|
|
+All methods accept an optional `style` parameter for custom console output styling.
|
|
|
+
|
|
|
+- `log.debug(message: string, style?: string): void`
|
|
|
+- `log.info(message: string, style?: string): void`
|
|
|
+- `log.warn(message: string, style?: string): void`
|
|
|
+- `log.error(message: string, style?: string): void`
|
|
|
+- `log.fatal(message: string, style?: string): void`
|
|
|
+
|
|
|
+### `log.log(message: string, level: string, style?: string): void`
|
|
|
+Generic log method where you specify the level.
|
|
|
+
|
|
|
+## Integration with Converse.js
|
|
|
+
|
|
|
+This package is used internally by Converse.js but can also be used independently in other projects.
|
|
|
+
|
|
|
+## Development
|
|
|
+
|
|
|
+To contribute or run tests locally:
|
|
|
+
|
|
|
+```bash
|
|
|
+git clone https://github.com/conversejs/converse.js.git
|
|
|
+cd src/log
|
|
|
+npm install
|
|
|
```
|
|
|
+
|
|
|
+## License
|
|
|
+
|
|
|
+MPL-2.0 © [Converse.js Contributors](https://github.com/conversejs/converse.js/graphs/contributors)
|