Reputation: 4474
I am using the laravel and trying to log the messages.
Log::info('[ProductViewModel/validate] First line message. \r\nSecond line message.');
Why \r\n
not working and just show the output like below.
[2016-03-21 10:17:43] local.INFO: [ProductViewModel/validate] First line message. \r\nSecond line message.
Upvotes: 4
Views: 9621
Reputation: 4705
I guess you should allow it in formatter options like:
$logger = new Monolog\Logger('MyLoggerName');
$formatter = new Monolog\Formatter\LineFormatter(
null, // Format of message in log, default [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n
null, // Datetime format
true, // allowInlineLineBreaks option, default false
true // ignoreEmptyContextAndExtra option, default false
);
$debugHandler = new Monolog\Handler\StreamHandler('/tmp/my_debug.log', Monolog\Logger::DEBUG);
$debugHandler->setFormatter($formatter);
$logger->pushHandler($debugHandler);
source: https://stepanoff.org/wordpress/2017/11/13/allow-inline-line-breaks-for-monolog/
Upvotes: 2
Reputation: 31
$data = [
'user id' => 'id',
'user verified email' => 'email'
];
$val = json_encode($data);
Log::channel('User_Activity')->info($val.PHP_EOL);
in json file happy Coding
Upvotes: 0
Reputation: 141
Use double quotes instead of single quotes around your log message, like so:
Log::info("[ProductViewModel/validate] First line message. \r\nSecond line message.");
Tabs also work with this approach (using \t).
Upvotes: 3
Reputation: 5443
you can use PHP_EOL as line break
Log::info('[ProductViewModel/validate] First line message'. PHP_EOL .'Second line message');
Upvotes: 18