# internal usage use Log::Report::Domain; my $domain = Log::Report::Domain->new(name => $name); # find a ::Domain object use Log::Report 'my-domain'; my $domain = textdomain 'my-domain'; # find domain config my $domain = textdomain; # config of this package # explicit domain configuration package My::Package; use Log::Report 'my-domain'; # set textdomain for package textdomain $name, %configure; # set config, once per program (textdomain $name)->configure(%configure); # same textdomain->configure(%configure); # same if current package in $name # implicit domain configuration package My::Package; use Log::Report 'my-domain', %configure;
# external file for configuration (perl or json format) use Log::Report 'my-domain', config => $filename; use Log::Report 'my-domain'; textdomain->configure(config => $filename);
See SYNOPSIS in Log::Report::Minimal::Domain
Log::Report can handle multiple sets of packages at the same time: in the usual case a program consists of more than one software distribution, each containing a number of packages. Each module in an application belongs to one of these sets, by default the domain set 'default'.
For Log::Report
, those packags sets are differentiated via the
text-domain value in the use
statement:
use Log::Report 'my-domain';
There are many things you can configure per (text)domain. This is not only related to translations, but also -for instance- for text formatting configuration. The administration for the configuration is managed in this package.
See DESCRIPTION in Log::Report::Minimal::Domain
Configuration of a domain can happen in many ways: either explicitly or implicitly. The explicit form:
package My::Package; use Log::Report 'my-domain'; textdomain 'my-domain', %configuration; textdomain->configure(%configuration); textdomain->configure(\%configuration); textdomain->configure(conf => $filename);
The implicit form is (no variables possible, only constants!)
package My::Package; use Log::Report 'my-domain', %configuration; use Log::Report 'my-domain', conf => '/filename';
You can only configure your domain in one place in your program. The textdomain setup is then used for all packages in the same domain.
This also works for Log::Report::Optional, which is a dressed-down version of Log::Report.
[0.91] The PRINTI
is a special constants for configure(formatter), and
will use String::Print function printi()
, with the standard tricks.
textdomain 'some-domain' formatter => { class => 'String::Print' # default , method => 'sprinti' # default , %options # constructor options for the class );
When you want your own formatter, or configuration of String::Print
,
you need to pass a CODE. Be aware that you may loose magic added by
Log::Report and other layers, like Log::Report::Template:
textdomain 'some-domain' , formatter => \&my_formatter;
Say, you log for a (Dancer) webserver, where you wish to include the website name in some of the log lines. For this, (ab)use the translation context:
### first enabled translation contexts use Log::Report 'my-domain', context_rules => {}; # or use Log::Report 'my-domain'; textdomain->configure(context_rules => {}); # or textdomain 'my-domain' , content_rules => {}; ### every time you start working for a different virtual host (textdomain 'my-domain')->setContext(host => $host); ### now you can use that in your code package My::Package; use Log::Report 'my-domain'; error __x"in {_context.host} not logged-in {user}", user => $username;