log_mf_h(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

🌸 NAME 🌸

log_mf_h β€” an event handler that logs events to disk, and yeah she does it fast πŸ’…

(this is an Erlang module definition bestie, chapter log_mf_h(3))


✨ DESCRIPTION ✨

Okay so listen. log_mf_h is a gen_event handler module, which basically means you can drop it into literally any gen_event process you want. And what does it do? It logs onto disk all the events that get sent to an event manager. All of them. Every single one. 🫢

Here's the slay part: each event is written as a binary, which makes the logging very fast. Like, silly fast. But β€” and this is the catch, bestie β€” that means you can't just open the file and read it like a normal human. You need a tool like the Report Browser (rb) to read those files. It's giving ✨encoded✨. Iykyk.

The events get written to multiple files. And when all the files have been used? The first one gets reused and overwritten. Gone. Recycled. Circle of life. πŸ”„

The directory location, the number of files, and the size of each file are all configurable, so you're in control, main character.

The directory will include one file called index, plus report files 1, 2, .... and so on forever (well, up to your MaxFiles, not forever forever 😭).

πŸ‘€ See Also

gen_event, rb


πŸŽ€ DATA TYPES πŸŽ€

  • -opaque args() β€” the Term to be sent to gen_event:add_handler/3. That's it, that's the whole vibe.
  • b() :: non_neg_integer().
  • f() :: 1..255.
  • pred() :: fun((term()) -> boolean()).

πŸ’– FUNCTIONS πŸ’–

init(Dir, MaxBytes, MaxFiles, Pred) -> Args

init(Dir, MaxBytes, MaxFiles, Pred) -> Args
    when
        Dir :: file:filename(),
        MaxBytes :: non_neg_integer(),
        MaxFiles :: 1..255,
        Pred :: fun((Event :: term()) -> boolean()),
        Args :: args().

This is the one that initiates the event handler, periodt. It returns Args, and you're gonna take that Args and use it in a call to:

gen_event:add_handler(EventMgr, log_mf_h, Args)

That's the whole ritual. No cap. 🌈

So what are all these arguments, bestie? Let me break it down:

  • Dir β€” specifies which directory to use for the log files. Where the magic happens. 🏠
  • MaxBytes β€” specifies the size of each individual file. How chunky each one gets before we move on.
  • MaxFiles β€” specifies how many files are used. Remember, when they're all used up, the first one gets overwritten β€” so pick this number with intention. πŸ’€
  • Pred β€” a predicate function used to filter the events. It's your lil bouncer at the door, deciding who gets in. If no predicate function is specified, all events are logged. Everyone's invited. πŸŽ‰
Fr fr, bookmark this one: if you don't pass a Pred, literally every event is getting written to disk. No filtering, no skipping, no mercy. Make sure that's what you actually want before you ship it. πŸ™ˆ

🌟 a lil sign-off 🌟

This lil masterpiece was brought to you by Ericsson AB, from stdlib version 8.0.4 β€” the log_mf_h(3) page. Mwah. πŸ’œ Go log some events, bestie, you got this. πŸ¦‹

πŸ“¦ where this page comes from