Metric...r::File(3pm)

πŸ’– NAME πŸ’–

Metrics::Any::Adapter::File β€” bestie, this one writes your metrics to a file. That's the whole vibe. πŸ“βœ¨


πŸ¦‹ SYNOPSIS πŸ¦‹

use Metrics::Any::Adapter 'File', path => "metrics.log";

okay that's it, one line, she's low maintenance πŸ’…


🌸 DESCRIPTION 🌸

So Metrics::Any has this adapter type, right, and what it does is take all the observations of your metric values and just… writes them into a file. That's it. That's the job. And honestly? Iconic. πŸ’–

Why would you want that, you ask? Because sometimes you're debugging, or you're testing some code that reports metrics, and you just wanna see what it's saying. No cap, this is the move. πŸ”

Like, say you set the METRICS_ANY_ADAPTER environment variable to configure the adapter β€” boom, now a metric log gets written as a side-effect of running a unit test:

$ METRICS_ANY_ADAPTER=File:path=metrics.log perl -Mblib t/01test.t

and then you just open up that generated file and peek at what metric values got reported while the program was running. it's giving detective energy πŸ•΅οΈβ™€οΈβœ¨

Now here's a little trick that's so underrated: if you point it at /dev/null, then the full metrics generation path gets tested β€” your code under test still sees a "real" adapter, but the output goes absolutely nowhere. Like a little black hole. Nothing comes out. πŸ•³οΈπŸ’€

$ METRICS_ANY_ADAPTER=File:path=/dev/null ./Build test

Heads up though: distribution and timing metrics are tracked with a running total and a count of observations. Keep that in mind when you're reading the output, bestie. πŸ“Š

🚨 Important, fr fr: this adapter type does NOT support batch mode reporting. Just so you know. Don't come for me. 😭

πŸŽ€ ARGUMENTS πŸŽ€

Here's the extra arguments she recognises (yes, plural grammar, no I did not write the original):

πŸ“ path

The path to the file to write to. That's it. Give her a path, she writes to it. Simple queen behavior πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk> β€” the icon, the legend, the main character who wrote this 🫢


and that's the whole page, bestie!! this was documented as part of perl v5.36.0, dated 2023-09-29 β€” go forth and log your metrics, you absolute gem πŸ’–βœ¨πŸŒΈπŸ¦‹πŸ’…

πŸ“¦ where this page comes from