Show HN: I've made an easy to extend and flexible JavaScript logger

github.com

16 points by inshinrei 2 days ago


hi! I've made a logger for JS/TS. It's easily extendable, easy to use and configure.

Would like to hear a feedback from you!

Thomaschaaf - 18 hours ago

Can you give insights into what makes it different from e.g. pino[1]? It's amazingly even faster than console.logging because of the way it buffers the data.

[1]: https://github.com/pinojs/pino

- a day ago
[deleted]
cluckindan - 14 hours ago

It would be great to have debug-like namespacing / filtering, combined with log levels.

https://www.npmjs.com/package/debug

gus_massa - a day ago

In case someone miss the link at the bottom of the readme, there is a detailed explanation in https://github.com/inshinrei/halua/blob/main/docs/tour_of_ha...

inshinrei - a day ago

i'm also leaving an example of production app setup here:

import {Level, halua, NewTextHandler, NewJSONHandler, NewWebConsoleHandler} from 'halua'

// an array of handlers that would accept logs

let handlers = [

  NewJSONHandler(writeToZipArchive, {level: Level.Info}), // writes to client-size archive, only logs that are Info-Level or higher

  NewTextHandler(sendToServer, {level: Level.Notice}), // writes to server, only logs tat are Notice-level or higher
  
  NewTextHandler(sendUserAction, {level: Level.Info + 1}), // we will log user actions on a different level, so that it will be easy to filter

  NewTextHandler(sendToErrorMonitoringSystem, {level: Level.Fatal}) // writes to monitoring system
]

if (debug) {

  handlers.push(NewWebConsoleHandler(self.console)) // writes to web / nodejs console
}

// now we have to apply the handlers we created

let logger = halua.New(handlers)

// or

halua.setHandler(handlers)

// later, you may call .New on any logger instance to get a new instance

lnxg33k1 - 15 hours ago

Doesn't seem flexible, seems mostly non-alterable, probably easily extendable is a thing, but I've been mostly productive with stuff that would allow me to don't duplicate existing behaviours but hook into them, that's flexibility imho, if I want to change some of the behaviour of an existing handler I have to reimplement it completely, then it's not flexible, the classes also seem quite giant, making me thing even more it's not really flexible/extendable