pulse00 / monolog-parser Goto Github PK
View Code? Open in Web Editor NEWA simple library for parsing monolog logfiles.
License: MIT License
A simple library for parsing monolog logfiles.
License: MIT License
The following line is not parsed properly:
[2017-05-31 14:16:19] testing.WARNING: DB - Query to get user_id for inactive login; logging only username in the table [] {"file":"/home/pawel/project/app/Http/Controllers/Auth/LoginController.php","line":108,"class":"App\\Http\\Controllers\\Auth\\LoginController","function":"check"}
The following code was used to test:
// where 'sample_log.log' contains the log statement above'
$reader = new LogReader('sample_log.log');
foreach ($reader as $logLine) {
var_dump($logLine);
}
Resulting parsing:
array(6) {
'date' =>
class DateTime#54 (3) {
public $date =>
string(26) "2017-05-31 14:16:19.000000"
public $timezone_type =>
int(3)
public $timezone =>
string(16) "America/New_York"
}
'logger' =>
string(7) "testing"
'level' =>
string(7) "WARNING"
'message' =>
string(70) "DB - Query to get user_id for inactive login; logging only username in"
'context' =>
NULL
'extra' =>
NULL
}
By inspecting the log statement above manually it is obvious that the 'message' was cut off and there does exist an 'extra' array with attributes but was not parsed either.
Hello,
i have tested your example and i get an error.
my code
$logFile = 'log/app.log';
$reader = new LogReader($logFile);
foreach ($reader as $log) {
echo sprintf("The log entry was written at %s. \n", $log['date']->format('Y-m-d h:i:s'));
}
My Logfile has 45 entries.
i get this error:
Call to a member function format() on null at line echo sprintf("The log entry was written at %s. \n", $log['date']->format('Y-m-d h:i:s'));
Hi there, do you have any plans to support Monolog 2.x
Hi.
I have a question about a monolog-parser.
var_dump($ log ['date']); displays this:
object(DateTime)#106 (3) {
["date"]=>
string(26) "2015-03-02 18:30:32.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Moscow"
}
If you write this line:
var_dump($log['date’]->date);
It displays an error:
Notice: Undefined property: DateTime::$date in /var/www/username/data/www/site.com/path/to/file.php on line 50
NULL
How to get a date?
Monolog allows writing multiline messages (with tracelog, for example). Here is an example:
[2020-03-25 16:27:13] report.ERROR: AMQP topology installation failed: stream_socket_client(): unable to connect to tcp://127.0.0.1:5672 (Connection refused)
#0 [internal function]: PhpAmqpLib\Wire\IO\StreamIO->error_handler(2, 'stream_socket_c...', '/home/dev/sites...', 141, Array)
#1 /home/dev/sites/project/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php(141): stream_socket_client('tcp://127.0.0.1...', 111, 'Connection refu...', 3, 4, Resource id #21711)
#2 /home/dev/sites/project/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(205): PhpAmqpLib\Wire\IO\StreamIO->connect()
#3 /home/dev/sites/project/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(189): PhpAmqpLib\Connection\AbstractConnection->connect()
#4 /home/dev/sites/project/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AMQPStreamConnection.php(60): PhpAmqpLib\Connection\AbstractConnection->__construct('rabbitmq', 'gabfey5qnqkCSze...', '/', false, 'AMQPLAIN', NULL, 'en_US', Object(PhpAmqpLib\Wire\IO\StreamIO), 0, 3)
#5 /home/dev/sites/project/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(116): PhpAmqpLib\Connection\AMQPStreamConnection->__construct('127.0.0.1', '5672', 'rabbitmq', 'gabfey5qnqkCSze...', '/', false, 'AMQPLAIN', NULL, 'en_US', 3, 3, NULL, false, 0)
#6 /home/dev/sites/project/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(66): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('PhpAmqpLib\\Conn...', Array)
#7 /home/dev/sites/project/vendor/magento/framework/ObjectManager/ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('PhpAmqpLib\\Conn...', Array)
#8 /home/dev/sites/project/vendor/magento/framework-amqp/Connection/Factory.php(43): Magento\Framework\ObjectManager\ObjectManager->create('PhpAmqpLib\\Conn...', Array)
#9 /home/dev/sites/project/vendor/magento/framework-amqp/Config.php(156): Magento\Framework\Amqp\Connection\Factory->create(Object(Magento\Framework\Amqp\Connection\FactoryOptions))
#10 /home/dev/sites/project/vendor/magento/framework-amqp/Config.php(169): Magento\Framework\Amqp\Config->createConnection()
#11 /home/dev/sites/project/vendor/magento/framework-amqp/TopologyInstaller.php(86): Magento\Framework\Amqp\Config->getChannel()
#12 /home/dev/sites/project/vendor/magento/module-amqp/Setup/Recurring.php(36): Magento\Framework\Amqp\TopologyInstaller->install()
#13 /home/dev/sites/project/setup/src/Magento/Setup/Model/Installer.php(1025): Magento\Amqp\Setup\Recurring->install(Object(Magento\Setup\Module\Setup), Object(Magento\Setup\Model\ModuleContext))
#14 /home/dev/sites/project/setup/src/Magento/Setup/Model/Installer.php(831): Magento\Setup\Model\Installer->handleDBSchemaData(Object(Magento\Setup\Module\Setup), 'schema', Array)
#15 /home/dev/sites/project/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php(122): Magento\Setup\Model\Installer->installSchema(Array)
#16 /home/dev/sites/project/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\UpgradeCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /home/dev/sites/project/vendor/symfony/console/Application.php(893): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /home/dev/sites/project/vendor/symfony/console/Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Magento\Setup\Console\Command\UpgradeCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /home/dev/sites/project/vendor/magento/framework/Console/Cli.php(105): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /home/dev/sites/project/vendor/symfony/console/Application.php(145): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /home/dev/sites/project/bin/magento(23): Symfony\Component\Console\Application->run()
#22 {main} [] []
Currently, it's not possible to parse such records. Would be cool to support such records
I have two types of log messages in my application: those generated by my logic and those generated by the framework. My messages don't typically have much supplemental information, but the framework messages often have variables, stack traces, and so on.
The parser will occasionally parse this extra information incorrectly, such as parsing the following line:
[2015-07-21 13:08:23] webapp.WARNING: ... (abbreviated) Trace: Cake\Error\BaseErrorHandler::handleError() ...
Into a message object that looks like this:
[ 'date' => false, 'logger' => 'Tra', 'level' => 'e', 'message' => '...', 'context' => null, 'extra' => (int) 37 ]
So as you can see, the parser is mistaking the word "Trace" for a logger/severity level and splitting it up into those respective array keys.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.