log_mf_h(3)
πΈ 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 togen_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
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms