@acryps/log
v0.0.0
Published
Log formatter
Downloads
115
Readme
Logger
Logs color coded messages to console.
D 2024-12-13T13:19:07 test-unit: i am a debug message
L 2024-12-13T13:19:08 test-unit: i am a log message
W 2024-12-13T13:19:09 test-unit: i am a warn message
E 2024-12-13T13:19:10 test-unit: i am a error messageconst importerLogger = new Logger('Importer');
for (let article of articles) {
const logger = importerLogger.child(article.id);
if (article.image != newImage) {
logger.log('updated image', newImage.hash);
}
}
Each unit gets a consistent color, based on its name.
Child Units
Branch into child logging units using the .task(name: string) or .child(name: string).
This will show both the parents and the child units name in the log output
Tasks can be finished using .finish(...messages).
Accessory
A unit can have an accessory generator, which can add essential dynamic information to the logging output. This can for example be used to show a queue length.
const logger = new Logger('compressor');
const queue = new Queue();
logger.accessory = () => `${queue.length}q`;
queue.dispatch(async task => {
async task.compress();
logger.log('compressed', task.name, 'from', task.source.size, 'to', task.compressed.size);
});
for (let file of uploads) {
queue.add(new CompressTask(file));
}L 2024-12-13T13:19:00 compressor (10q): compressed hello-1.mp4 from 11123 to 4001
L 2024-12-13T13:19:00 compressor (9q): compressed hello-2.mp4 from 3123 to 512
L 2024-12-13T13:19:00 compressor (8q): compressed hello-3.mp4 from 44412 to 3251
L 2024-12-13T13:19:00 compressor (13q): compressed hello-4.mp4 from 13662 to 3111This shows that new files must have been added to the queue betwen the 3. and 4. import.
