Skip to content

Commit

Permalink
replace systemd detection with the MOJO_LOG_SHORT environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 14, 2017
1 parent de71a04 commit 4319b69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,9 +1,11 @@

7.40 2017-08-12
7.40 2017-08-14
- Added support for Role::Tiny extensions to all classes based on Mojo::Base.
(dotan)
- Added with_roles method to Mojo::Base. (dotan)
- Added the guide Mojolicious::Guides::Testing. (scottw)
- Replaced systemd detection in Mojo::Log with the MOJO_LOG_SHORT environment
variable, since there is no reliable way to detect systemd.

7.39 2017-08-03
- Removed experimental close_idle_connections method from
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojo/Log.pm
Expand Up @@ -19,8 +19,7 @@ has history => sub { [] };
has level => 'debug';
has max_history_size => 10;
has 'path';
has short =>
sub { $ENV{INVOCATION_ID} && $ENV{JOURNAL_STREAM} && !shift->path };
has short => sub { $ENV{MOJO_LOG_SHORT} };

# Supported log levels
my %LEVEL = (debug => 1, info => 2, warn => 3, error => 4, fatal => 5);
Expand Down Expand Up @@ -178,8 +177,7 @@ Log file path used by L</"handle">.
$log = $log->short($bool);
Generate short log messages without a timestamp, suitable for systemd, defaults
to auto-detection based on the presence of a L</"path"> and the
C<INVOCATION_ID> and C<JOURNAL_STREAM> environment variables.
to the value of the C<MOJO_LOG_SHORT> environment variables.
=head1 METHODS
Expand Down
15 changes: 6 additions & 9 deletions t/mojo/log.t
Expand Up @@ -50,22 +50,19 @@ $log->format(
like $log->format->(time, 'debug', qw(Test 1 2 3)), qr/^debug:\d+:Test:1:2:3$/,
'right format';

# systemd
# Short log messages
{
$log = Mojo::Log->new;
ok !$log->short, 'systemd has not been detected';
ok !$log->short, 'long messages';
like $log->format->(time, 'debug', 'Test 123'),
qr/^\[.*\] \[debug\] Test 123\n$/, 'right format';
local $ENV{JOURNAL_STREAM} = '1:23456';
local $ENV{INVOCATION_ID} = 1;
local $ENV{MOJO_LOG_SHORT} = 1;
$log = Mojo::Log->new;
ok $log->short, 'systemd has been detected';
ok $log->short, 'short messages';
$log = Mojo::Log->new(short => 1);
ok $log->short, 'short messages';
like $log->format->(time, 'debug', 'Test 123'), qr/^\[debug\] Test 123\n$/,
'right format';
$log = Mojo::Log->new(path => $path);
ok !$log->short, 'a path will be used';
like $log->format->(time, 'debug', 'Test 123'),
qr/^\[.*\] \[debug\] Test 123\n$/, 'right format';
}

# Events
Expand Down

0 comments on commit 4319b69

Please sign in to comment.