Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marc-ed-raffalli/vanilla-space-logger
A vanilla JS console logger with levels, namespace and colors
https://github.com/marc-ed-raffalli/vanilla-space-logger
console logger namespace vanilla-js
Last synced: 3 days ago
JSON representation
A vanilla JS console logger with levels, namespace and colors
- Host: GitHub
- URL: https://github.com/marc-ed-raffalli/vanilla-space-logger
- Owner: marc-ed-raffalli
- License: mit
- Created: 2024-08-09T18:02:08.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-12T19:29:55.000Z (5 months ago)
- Last Synced: 2024-11-09T23:09:00.095Z (2 months ago)
- Topics: console, logger, namespace, vanilla-js
- Language: TypeScript
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vanilla Space Logger πͺ΅
Welcome to **Vanilla Space Logger**!
This is a simple yet handy logging utility for JS/TS developers who love a bit of color and organization in their console logs.
With **Vanilla Space Logger**, you can easily organize your logs by namespaces and quickly read through them thanks to the custom color coding.
Logs deserve some TLC too, why should they be messy and ignored? πNote: this package is designed to help with quick PoC and simple applications rather than large systems in production.
## π Features
- π¦ **Vanilla:** Leverages the native `console` API: (`error`, `warn`, `info`, `log`, `debug` and `trace`).
No additional dependencies- π¨π **Space:** Organize your logs by grouping them under specific namespaces.
Easily extend these namespaces into sub namespaces. No more hunting for relevant logs!- πͺ΅ **Logger**: Choose which level of logs to be printed out.
Note: string substitution e.g. `Age: %d` is not supported in this mvp/initial version.
Feel free to file an issue/upvote the feature on GitHub.## π¦ Installation
### Yarn
```shell
yarn add vanilla-space-logger
```### PNPM
```shell
pnpm install vanilla-space-logger
```### NPM
```shell
npm install vanilla-space-logger
```## π οΈ Usage
Hereβs a quick example to give you an overview:
```javascript
import { makeLogger } from 'vanilla-space-logger';// Create a logger instance, the printed color is derived from the namespace string
const logger = makeLogger('TodoList');logger.error('Sample error message', 123, 456);
// prints "TodoList:Sample error message 123 456"
logger.warn('Sample warning message');
logger.info('Sample info message');
logger.log('Sample log message');
logger.debug('Sample debug');
logger.trace('Sample trace');const apiLogger = logger.extend('API');
const storeLogger = logger.extend('store');apiLogger.error('HTTP error message');
// prints "TodoList:API:HTTP error message"
storeLogger.trace('updating task...');
// prints "TodoList:store:updating task..."
```## π§ Options
```javascript
const options: LoggerOptions = {
// lower log level to print
level: 'info',
// hash function returning a color/hex based on the namespace value
generateHexColorFromNamespace: (namespace: string) => '#123456',
};makeLogger('TodoList', options);
```