News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lorna Mitchell:
Logging to Stdout with Monolog
June 09, 2014 @ 09:08:10

Lorna Mitchell has a quick post today showing how you can use the popular Monolog logging library to log messages and data to stdout, the standard output stream of whatever is executing the script.

My worker scripts have really basic logging (as in, they echo when something happens, and I can see those in the supervisord logs). Which is kind of okay, but I wanted to at least add timestamps in to them, and maybe send emails when something REALLY bad happened. I'm a huge fan of Monolog so I grabbed that, but it wasn't immediately obvious which of the many and varied options I would need for this fairly simple addition. It turns out that the right thing to use is the ErrorLogHandler.

She includes a few lines of sample code that use the "ErrorLogger" to output the message. It includes the log level, a timestamp, the message itself and any additional contextual information you pass in.

0 comments voice your opinion now!
monolog stdout output example library logging

Link: http://www.lornajane.net/posts/2014/logging-to-stdout-with-monolog

Liip Blog:
New in Symfony 2.4 Show logs in console
August 21, 2013 @ 10:53:44

On the Liip blog they've shared a new post from Tobias Schultze about a new feature that will be in the 2.4 release of the popular Symfony framework - the ability to show log messages in console output.

When you want to output text to the console you usually used the OutputInterface instance that is passed when your command gets executed. But there are two problems: it's cumbersome to print information depending on the verbosity settings and if the service you call also wants to give feedback you would need to pass on the $output. [...] To solve these [two problems] I thought it would be much easier to rely on the logger which is highly related. So I added integration between Symfonys Console Component and Symfonys logging library Monolog in PR #8167.

This gives you a new handler, the ConsoleHandler, that makes it easier to just write out based on console events instead of just appending to the output. It includes switches for verbosity levels too. He shows how to implement it in your application, configuring it through the YAML config both in the service and under the Monolog settings as a handler.

0 comments voice your opinion now!
symfony2 log console command component consolehandler monolog

Link: http://blog.liip.ch/archive/2013/08/20/new-in-symfony-2-4-show-logs-in-console.html

Sameer Borate:
Debugging Laravel with MonoLog and FirePHP
June 07, 2013 @ 09:08:37

Sameer Borate has a new post to his site showing you how to debug a Laravel application with Monolog and FirePHP.

By default, Laravel is configured to create daily log files for your application, and are stored in app/storage/logs. All Laravel logging features are handled by the wonderful MonoLog library. Monolog includes various log handlers you can use - FirePHP, ChromePHP, CouchDB, Stream and many more. One of my favorites is FirePHP while debugging PHP apps.

Getting Monolog to write out to FirePHP is pretty easy and he includes the sample code to make it happen - basically pushing a "FirePHPHandler" into the Monolog instance and using it from there.

0 comments voice your opinion now!
debug laravel monolog firephp handler tutorial

Link: http://www.codediesel.com/laravel/debuggin-laravel-with-monolog-and-firephp

PHPMaster.com:
Logging with PSR-3 to Improve Reusability
February 07, 2013 @ 10:22:26

On PHPMaster.com Patrick Mulvey has written up a new tutorial looking at using the PSR-3 logging structure to make a basic logger for your application.

Logging is one of the most ubiquitous tasks encountered in PHP. We use logs to track error messages, record important events, and debug problems with our code. In any PHP project, the code is likely to be full of calls to a logging library which handles these actions for us. [...] To promote compatibility between logging libraries, the PHP-FIG group recently released PRS-3, a common interface for logger objects. In this article, I'll discuss how the logger interface defined by PSR-3 allows us to write reusable code that isn't dependent on any particular logging implementation.

He includes a quick introduction to the PSR-3 format, how to get the files you'll need to use it (via Composer). He includes some sample code showing how to make the basic email class with a logger injected for use. Since the Monolog logging project follows the PSR-3 format, it's an easy drop-in option. He also talks about using PSR-3 to avoid having logger dependencies with the "LoggerInterface". There's also a bit at the end of the tutorial showing you how to use the Adapter design pattern to "proxy" the logging calls to the class via a PSR-3 interface.

0 comments voice your opinion now!
psr3 logging reusability tutorial monolog dependency adapter designpattern


Jeremy Cook:
Turbocharging your Logs
October 03, 2012 @ 10:07:30

In a new post to his site Jeremy Cook introduces you to Graylog2, a logging server that can aggregate messages from multiple sources/feeds into one consolidated location.

Graylog stores them in a database and allows you to perform custom searches on them. You can also see in real time how many log messages are being received and processed. The real killer feature in Graylog is streams. A stream in Graylog is a predefined custom search. The server will display to you log messages that only match the stream criteria selected, graphing the results for you.

He mentions other features of the Graylog2 system including customized alerts, messaging via UDP/AMQP and how it uses MongoDb and ElasticSearch. He also introduces Monolog, a PHP tool that lets you log in multiple formats directly to the Graylog2 server. He includes an example of how it works with a sample "LoggingHelper" added as custom exception and error handlers.

0 comments voice your opinion now!
graylog2 tutorial monolog aggregate logging tutorial



Community Events





Don't see your event here?
Let us know!


opinion zendserver introduction symfony bugfix tips framework language library developer interview api threedevsandamaybe deployment release community laravel series podcast list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework