Skip to content

Instantly share code, notes, and snippets.

@jkramer jkramer/Log::Dispatch.pm6
Last active Sep 26, 2016

Embed
What would you like to do?
Log::Dispatch for Perl 6
class Log::Dispatch {
enum Level <DEBUG INFO NOTICE WARNING ERROR CRITICAL ALERT EMERGENCY>;
class Output {
has Level $.level = DEBUG;
method format(Level $level, DateTime $ts, @args) {
$ts ~ ' [' ~ $level.lc ~ '] ' ~ @args>>.gist.join(' ')
}
method output(Str $msg) { ... }
}
class Screen is Output {
method output(Str $msg) { $msg.note }
}
has Output @.outputs is rw;
method log(Level $level, *@things) {
my $ts = DateTime.now;
@!outputs>>.&{.output(.format($level, $ts, @things)) if $level >= .level};
}
for Level::.values -> $level {
::?CLASS.^add_method(
$level.lc,
method (*@things) { $.log($level, @things) }
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.