=begin pod =NAME Log =VERSION 0.3.1 =AUTHOR Patrick Spek =head1 Description An interface for logging mechanisms in the Raku programming language to adhere to. L has been used as a reference point to decide which levels to support, and what naming conventions to use. =head2 Intention This module has been created to serve as an interface to which logging mechanisms in Raku can adhere. A standardized interface for handling logging will make it easier for all projects to get started with logging, while allowing application handlers to adjust all logging to suit their current application. =head2 Usage Any class that wants to handle logging in Raku can implement the C role. use Log::Implementation; unit class Log::Custom is Log::Implementation { … } To do the actual logging, C exports an C level C<$instance> variable. This should be set in the main application, and used (preferably using C) in modules. =head3 For library developers Throughout your library, you can use any of the 8 methods that a C implementation must support: =item C =item C =item C =item C =item C =item C =item C =item C There's no guarantee that C is implemented in an application, for any reason of the application's developer. Luckily, Raku has a terse way to work with this reality, using the C control flow statement. .info('This is an informational message') with $Log::instance; If C<$Log::instance> is defined, C<.info> will be called on it. Otherwise, this statement is skipped. This allows application developers to decide if they want any logging, and which C implementation to use. =head3 For application developers Much like library developers, you can use the same methods to add logging to your application. However, the application must also set up the C<$Log::instance> variable, the C module doesn't set it to anything. $Log::instance = Log::Simple.new; You should probably also add one or more outputs. These must be C objects. To send all logging to C, add C<$*ERR> as output. $Log::instance.add-output($*ERR); You can specify a minimum log level for each output, and optionally a Callable to act as filter. $Log::instance.add-output($*ERR, Log::Level::Debug, filter => sub (%payload) { %payload ~~ /Foo/ # Only send messages containing "Foo" }); =head4 Environment variables There are some environment variables that must be honored. These are intended to allow the user to customize the logging into what works for I. =head5 C When set, the class name defined in this environment variable must be used to populate the C<$Log::instance> variable. This can be implemented using a C statement and use of the I operator. $Log::instance = (require ::(%*ENV // 'Log::Simple')).new; =head5 C When set, this should override the log level used in the application. This is easily implemented using the I operator in your code. $Log::instance.add-output($*ERR, %*ENV // Log::Level::Info); =head1 Installation Install this module through L: =begin code :lang zef install Log =end code =head1 Documentation Documentation is written as L documents, and can be read with the L|https://modules.raku.org/dist/p6doc:github:perl6> module. =begin input p6doc Log =end input At your option, you can also use prettier readers, such as L|https://modules.raku.org/dist/App::Rakuman:cpan:TYIL>. =begin input rakuman Log =end input =head1 License This module is distributed under the terms of the LGPL-3.0-only. =end pod