Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
monologで例外のstack traceをいい感じに表示する
{
"require": {
"monolog/monolog": "^1.23"
}
}
<?php
require_once 'vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
$log1 = new Logger('いい感じにみえないやつ');
$log1->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
$log2 = new Logger('いい感じにみえるやつ');
$handler = new StreamHandler('php://stdout', Logger::DEBUG);
$formatter = new LineFormatter();
$formatter->includeStacktraces(true);
$log2->pushHandler($handler->setFormatter($formatter));
function a() {
throw new \Exception('aaa');
}
function b() {
try {
a();
} catch (\Exception $e) {
throw new \Exception('bbb', 0, $e);
}
}
function c() {
try {
b();
} catch (\Exception $e) {
throw new \Exception('ccc', 0, $e);
}
}
try {
c();
} catch (\Exception $e) {
$log1->error($e);
$log2->error($e);
}
@ara-ta3

This comment has been minimized.

Copy link
Owner Author

commented Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.