Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers below. Special handlers allow you to build advanced logging strategies.
// Create the main logger of the app $logger = newLogger('my_logger'); $logger->pushHandler($stream); $logger->pushHandler($firephp);
// Create a logger for the security-related stuff with a different channel $securityLogger = newLogger('security'); $securityLogger->pushHandler($stream); $securityLogger->pushHandler($firephp);
// Or clone the first one to only change the channel $securityLogger = $logger->withName('security');
// you can use your logger $logger->info('My logger is now ready');
自定义日志格式
1 2 3 4 5 6 7 8 9 10 11 12 13
// the default date format is "Y-m-d H:i:s" $dateFormate = "Y n j, g:i a"; // the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n" $output = "%datetime% > $level_name% > %message% %content% %extra%\n"; // finally, create a formatter $formatter = newLineFormatter($output, $dateFormat);
// Create a handler $stream = newStreamHandler(__DIR__ . '/my_app.log', Logger::DEBUG); $stream->setFormatter($formatter); // bind it to a logger object $securityLogger = newLogger('sucurity'); $securityLogger->pushHandler($stream);