Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
short log messages can span multiple lines, and each line needs a mag…
…ic number prefix
  • Loading branch information
kraih committed Feb 7, 2018
1 parent bedc440 commit a232820
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

7.64 2018-02-07
- Fixed a bug in Mojo::Log where short log messages spanning multiple lines
would not be formatted properly for systemd.

7.63 2018-02-06
- Improved Mojo::Log to use native systemd log levels.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Log.pm
Expand Up @@ -72,7 +72,8 @@ sub _message {

sub _short {
my ($time, $level) = (shift, shift);
return "<$MAGIC{$level}>[" . substr($level, 0, 1) . '] ' . join "\n", @_, '';
my ($magic, $short) = ("<$MAGIC{$level}>", substr($level, 0, 1));
return "${magic}[$short] " . join("\n$magic", @_) . "\n";
}

1;
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/log.t
Expand Up @@ -50,7 +50,7 @@ $log->format(
like $log->format->(time, 'debug', qw(Test 1 2 3)), qr/^debug:\d+:Test:1:2:3$/,
'right format';

# Short log messages
# Short log messages (systemd)
{
$log = Mojo::Log->new;
ok !$log->short, 'long messages';
Expand All @@ -71,6 +71,8 @@ like $log->format->(time, 'debug', qw(Test 1 2 3)), qr/^debug:\d+:Test:1:2:3$/,
'right format';
like $log->format->(time, 'fatal', 'Test 123'), qr/^<2>\[f\] Test 123\n$/,
'right format';
like $log->format->(time, 'debug', 'Test', '1', '2', '3'),
qr/^<7>\[d\] Test\n<7>1\n<7>2\n<7>3\n$/, 'right format';
}

# Events
Expand Down

0 comments on commit a232820

Please sign in to comment.