1Log::Fmt(3) User Contributed Perl Documentation Log::Fmt(3)
2
3
4
6 Log::Fmt - a little parser and emitter of structured log lines
7
9 version 3.004
10
12 This library primarily exists to service Log::Dispatchouli's
13 "log_event" methods. It converts an arrayref of key/value pairs to a
14 string that a human can scan tolerably well, and which a machine can
15 parse about as well. It can also do that tolerably-okay parsing for
16 you.
17
19 This library should run on perls released even a long time ago. It
20 should work on any version of perl released in the last five years.
21
22 Although it may work on older versions of perl, no guarantee is made
23 that the minimum required version will not be increased. The version
24 may be increased for any reason, and there is no promise that patches
25 will be accepted to lower the minimum required perl.
26
28 format_event_string
29 my $string = Log::Fmt->format_event_string([
30 key1 => $value1,
31 key2 => $value2,
32 ]);
33
34 Note especially that if any value to encode is a reference to a
35 reference, then String::Flogger is used to encode the referenced value.
36 This means you can embed, in your logfmt, a JSON dump of a structure by
37 passing a reference to the structure, instead of passing the structure
38 itself.
39
40 parse_event_string
41 my $kv_pairs = Log::Fmt->parse_event_string($string);
42
43 Given the kind of string emitted by "format_event_string", this method
44 returns a reference to an array of key/value pairs.
45
46 This isn't exactly a round trip. First off, the formatting can change
47 illegal keys by replacing characters with question marks, or replacing
48 empty strings with tildes. Secondly, the formatter will expand some
49 values like arrayrefs and hashrefs into multiple keys, but the parser
50 will not recombined those keys into structures. Also, there might be
51 other asymmetric conversions. That said, the string escaping done by
52 the formatter should correctly reverse.
53
54 If the input string is badly formed, hunks that don't appear to be
55 value key/value pairs will be presented as values for the key "junk".
56
58 Ricardo SIGNES <cpan@semiotic.systems>
59
61 This software is copyright (c) 2023 by Ricardo SIGNES.
62
63 This is free software; you can redistribute it and/or modify it under
64 the same terms as the Perl 5 programming language system itself.
65
66
67
68perl v5.36.1 2023-06-06 Log::Fmt(3)