.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Log::Fmt 3pm" .TH Log::Fmt 3pm "2023-09-03" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Log::Fmt \- a little parser and emitter of structured log lines .SH "VERSION" .IX Header "VERSION" version 3.007 .SH "OVERVIEW" .IX Header "OVERVIEW" This library primarily exists to service Log::Dispatchouli's \f(CW\*(C`log_event\*(C'\fR methods. It converts an arrayref of key/value pairs to a string that a human can scan tolerably well, and which a machine can parse about as well. It can also do that tolerably-okay parsing for you. .SH "PERL VERSION" .IX Header "PERL VERSION" This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years. .PP Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. .SH "METHODS" .IX Header "METHODS" .SS "format_event_string" .IX Subsection "format_event_string" .Vb 4 \& my $string = Log::Fmt\->format_event_string([ \& key1 => $value1, \& key2 => $value2, \& ]); .Ve .PP Note especially that if any value to encode is a reference \fIto a reference\fR, then String::Flogger is used to encode the referenced value. This means you can embed, in your logfmt, a \s-1JSON\s0 dump of a structure by passing a reference to the structure, instead of passing the structure itself. .SS "parse_event_string" .IX Subsection "parse_event_string" .Vb 1 \& my $kv_pairs = Log::Fmt\->parse_event_string($string); .Ve .PP Given the kind of string emitted by \f(CW\*(C`format_event_string\*(C'\fR, this method returns a reference to an array of key/value pairs. .PP This isn't exactly a round trip. First off, the formatting can change illegal keys by replacing characters with question marks, or replacing empty strings with tildes. Secondly, the formatter will expand some values like arrayrefs and hashrefs into multiple keys, but the parser will not recombined those keys into structures. Also, there might be other asymmetric conversions. That said, the string escaping done by the formatter should correctly reverse. .PP If the input string is badly formed, hunks that don't appear to be value key/value pairs will be presented as values for the key \f(CW\*(C`junk\*(C'\fR. .SS "parse_event_string_as_hash" .IX Subsection "parse_event_string_as_hash" .Vb 1 \& my $hashref = Log::Fmt\->parse_event_string_as_hash($line); .Ve .PP This parses the given line as logfmt, then puts the key/value pairs into a hash and returns a reference to it. .PP Because nothing prevents a single key from appearing more than once, you should use this with the understanding that data could be lost. No guarantee is made of which value will be preserved. .SH "AUTHOR" .IX Header "AUTHOR" Ricardo \s-1SIGNES\s0 .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2023 by Ricardo \s-1SIGNES.\s0 .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.