https://github.com/cheminfo/fifo-logger
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.1%) to scientific vocabulary
Keywords from Contributors
Repository
Basic Info
- Host: GitHub
- Owner: cheminfo
- License: mit
- Language: TypeScript
- Default Branch: main
- Homepage: https://cheminfo.github.io/fifo-logger/
- Size: 269 KB
Statistics
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 1
- Releases: 16
Metadata Files
README.md
fifo-logger
Simple event logger for the browser and Node.js inspired by pino.
By default, it will keep the 10'000 last events that can easily be retrieved and filtered.
Installation
console
npm install fifo-logger
Simple usage
```js import { FifoLogger } from 'fifo-logger';
const logger = new FifoLogger({ limit: 1000, // default value level: 'info', // by default we will not log the level under 'info' (trace and debug) });
logger.trace('a trace'); logger.debug('a debug'); logger.info('an info'); logger.warn('a warning'); logger.error('a error'); logger.fatal('fatal');
// you have also the possibility to log an object or object + message
logger.warn({ a: 1, b: 2, c: 'Hello' }, 'a warning');
// errors can also be directly added to the logger
logger.fatal(new Error('a fatal error'));
// to get the logs
const logs = logger.getLogs(); ```
Logging in a specific context
A child logger may be created in order to store specific related logs. Each logger or child logger will receive a specific UUID.
```js import { FifoLogger } from 'fifo-logger';
const logger = new FifoLogger(); logger.info('an info');
const childLogger = logger.child(); childLogger.info('from child');
const grandChildLogger = childLogger.child(); grandChildLogger.info('from grandchild');
const anotherLogger = logger.child(); anotherLogger.info('from another child');
console.log(logger.getLogs()); // 1 element console.log(logger.getLogs({ includeChildren: true })); // 4 elements console.log(childLogger.getLogs()); // 1 element console.log(childLogger.getLogs({ includeChildren: true })); // 3 elements ```
Callback when new logs are added
If you need to update the log list based on new addition you can add the onChange callback
```js const logger = new FifoLogger({ onChange: (log, logs, info) => { console.log(log, logs, info); }, }); logger.info('Hello world');
// info contains 'depth' starting at 1 ```
Callback with throttling
Libraries may be quite verbose and you can throttle the callback using such a code
```js import { throttle } from 'throttle-debounce';
import { FifoLogger } from 'fifo-logger';
let results: any = [];
let throttleFunc = throttle(100, (log, logs) => { results.push(log.message); results.push(logs.length); });
const logger = new FifoLogger({ onChange: throttleFunc, });
logger.info('first info'); logger.info('second info');
const start = Date.now(); while (Date.now() - start < 120);
logger.info('an info after 120ms');
console.log(results); // ['first info', 1, 'an info after 120ms', 3] ```
In the browser
``html
<html>
<head>
<script
src="https://www.lactame.com/lib/fifo-logger/0.3.0/fifo-logger.js"
type="text/javascript"
></script>
<script Logger="fifo-logger" type="text/javascript">
const logger = new FifoLogger.FifoLogger({
onChange: (log, logs) => {
console.log(logs);
document.getElementById('logs').innerHTML =
'<table><tr><th>Level</th><th>Message</th></tr>' +
logs
.map((log) => {
return
<script>
logger.info('Hello World!');
logger.error('This is an error');
</script>