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

Emir Karsiyakali:
Quick Tip - Logging Mastery with Laravel
Jul 02, 2018 @ 18:54:11

In this new post to his site Emir Karsiyakali shares a quick tip for the Laravel users out there to improve your logging output and make following requests easier.

Putting unique id to requests one of my silver bullet while designing RESTful APIs. It provides an extremely easy way to follow each request’s lifecycle while debugging. In this guide I’ll show you how you can add it to your log files on Laravel 5.6.

Under the hood, Laravel utilizes the Monolog library, which provides support for a variety of powerful log handlers. Laravel makes it a cinch to configure these handlers, allowing you to mix and match them to customize your application’s log handling.

He starts with adding the "tap" value to the logger configuration and pointing it to a newly created LocalLogger class. He shows the implementation of this logger class including a custom log formatter that will modify the log string to add the unique ID after the "datetime" value. He also includes some usage examples in your Laravel code, putting the Log::info line into a LogRequestResponse middleware to be executed on each request.

tagged: laravel tutorial log unique id monolog

Link: https://emirkarsiyakali.com/quick-tip-logging-mastery-with-laravel-7282988032a7

Amazon AWS:
PHP application logging with Amazon CloudWatch Logs and Monolog
May 07, 2018 @ 14:13:46

The Amazon AWS blog has posted a tutorial helping you get started using Amazon CloudWatch logging from PHP. CloudWatch is a logging service offered by Amazon that comes with features making it easier to track metrics, set alarms and monitor log files.

Logging and information debugging can be approached from a multitude of different angles. Whether you use an application framework or coding from scratch it’s always comforting to have familiar components and tools across different projects. In our examples today, I am going to enable Amazon CloudWatch Logs logging with a PHP application. To accomplish this, I wanted to use an existing solution that is both already popular and well used, and that is standards compliant. For these reasons, we are going to use the open source log library, PHP Monolog.

They start the tutorial with a brief overview of both Monolog and the CloudWatch logging service. From there they help you get the AWS PHP SDK and Monolog installed and an add-on that lets Monolog talk to CouldWatch. The post then provides some example code showing how to set up the PHP-to-CloudWatch connection and what the logging result looks like. They also include instructions on setting up logging filters/metrics and, as a bonus, how to use CloudWatch logging in a Laravel application.

tagged: cloudwatch logging tutorial setup configure monolog addon filter matric

Link: https://aws.amazon.com/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/

Pehapkari.cz:
How to connect ELK with Monolog
Oct 23, 2017 @ 15:48:59

On the Pehapkari.cz blog there's a new tutorial posted showing you how to integrate ELK and Monolog for simpler to use and more robust log handling.

ELK is awesome stack for logging. Monolog is awesome PHP logging library. Let's make them work together. [...] In a nutshell, Monolog offers you a logger, where you send your logs. This logger has multiple handlers, which send these logs wherever you need them. Monolog has many handlers, which enable you to to simply send logs to many destinations, e.g. files, e-mails, slack, logstash, and many more. [...] ELK stack (now known as Elastic stack) stands for Elasticsearch, Logstash, Kibana stack.

After briefly introducing both technologies the author then gets into the integration, showing how to use either the ElasticSearchHandler or Gelf to ship the logs over for handling. Monolong includes the handler to make this work and the post includes the code/configuration to use it. With the logs being sent out the next step is to set up where you're sending them to. In this case it's a RabbitMQ setup that will then send them along to Logstash. Configuration for this is included as well.

tagged: elk logstash elasticsearch kibana tutorial monolog package integration

Link: https://pehapkari.cz/blog/2017/10/22/connecting-monolog-with-ELK/

Nikola Posa:
Using Monolog with Zend Service Manager
Jun 16, 2017 @ 17:09:27

Nikola Posa has a new post to his site showing you how to can combine Monolog for logging with Zend Service Manager, a component from the Zend Framework, defining the logger as a service that can be easily used (and re-used) across an application.

Without any doubt, Monolog and Zend Service Manager are two libraries that are almost always found in the composer.json file require section of my projects. In case you didn't know, Monolog is a PSR-3 compliant logging library that allows you to save logs to various storage types and web services, while Zend Service Manager is a PSR-11 compliant dependency injection container and a service locator implementation that facilitates management of application dependencies.

In this post I'm gonna show you how the two can work together.

He starts with an example of configuring the ServiceManager instance with a factory dependency that manually creates the Monolog logger inline. While this works, it's not idea, mixing configuration and functionality. He shows how to refactor the same functionality into a factory class that performs the same function but isolates it from the configuration. He then takes this further and separates out the environment-specific configuration from the handling and, finally, shows the creation of a more general logging factory that allows the definition of different kinds of loggers based on the need.

tagged: monolog zendservicemanager component tutorial combine factory configuration

Link: http://blog.nikolaposa.in.rs/2017/06/12/using-monolog-with-zend-service-manager/

Amazon Web Services:
PHP application logging with Amazon CloudWatch Logs and Monolog
Apr 24, 2017 @ 14:46:47

On the Amazon Web Services blog there's a new post showing you how to use the Monolog logging library and a custom AWS extension to ship your logs to Amazon CloudWatch quickly and easily.

Logging and information debugging can be approached from a multitude of different angles. Whether you use an application framework or coding from scratch it’s always comforting to have familiar components and tools across different projects. In our examples today, I am going to enable Amazon CloudWatch Logs logging with a PHP application. To accomplish this, I wanted to use an existing solution that is both already popular and well used, and that is standards compliant. For these reasons, we are going to use the open source log library, PHP Monolog (https://github.com/Seldaek/monolog).

They start by introducing the Monolog library for those not familiar with it and how it relates to the PSR-3 standard. The ultimate goal with their implementation is to allow for the logs to be shipped to CloudWatch and implement some alerting around them. The tutorial then kicks in and they show you how to use Composer to install Monolog and an add-on to interface with CloudWatch. Code is provided to set up the initial logger and how to have it to log messages to different places. They then move over to CloudWatch and define a filter for the JSON data to find successful logins to your application. They also show how to use this same functionality in a Laravel application, contained in a test route.

tagged: aws amazon logging cloudwatch monolog tutorial install usage filter

Link: https://aws.amazon.com/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/

Stefano Alletti:
Symfony and Monolog, how use Processor in your project: a practical example
Mar 17, 2017 @ 17:23:44

Stefano Alletti has written up a post to his site showing how to combine Symfony and Monolog along with a custom "processor" to modify the message and content being logged.

We often have to use different micro-services who write in many log files. Use utilities like Kibana is a good thing, but in order to take full advantage of its features we have to try to standardize and normalize the logs.

The company where I work having introduced Kibana recently, he asked me to implement a proper strategy to log all the micro-services.

He starts by outlining the fields that are required to be in the log output (a great place to start) before moving into the code to implement the logging. He briefly talks about Monolog itself and how to implement it in a Symfony application. The remainder of the post includes the code to implement the logger and how to add the custom processor to modify the extra data being included in the logged data. He also goes a step further and creates a custom formatter to modify the output in the message for the customer ID and product line values.

tagged: tutorial symfony monolog processor formatter integration

Link: https://stefanoalletti.wordpress.com/2017/03/09/symfony-and-monolog-how-use-processor-in-your-project/

Jordi Boggiano:
The Road to Monolog 2.0
Dec 23, 2015 @ 17:18:01

Fans of the Monolog logging library (used by loads of major PHP-based projects too) will be interested in checking out this post about version 2 from Jordi Boggiano, lead developer on the project.

Monolog's first commit was on February 17th, 2011. That is almost 5 years ago! I have now been thinking for quite a while that it would be nice to start on a v2, and being able to drop some baggage.

One of the main questions when doing a major release is which minimum PHP version to support going forward. Last summer I decided I wanted to do a big jump from 5.3 and directly target PHP 7. It provides a lot of nice features as well as performance improvements, and as Monolog is one of the most installed packages on Packagist I wanted to help nudge everyone towards PHP 7.

Now that PHP 7 has been released, he's moving even more towards this goal for version 2 of the popular tool. He talks about "the road forward" and links to a milestone that's been set up with issues to correct and features to update before v2.0 can be called stable. He does offer a word of warning too - if you use dev-master for your Composer installs, update it to use ^1.17 instead as the main branch will break soon with the work for v2.

tagged: monolog v2 php7 major release upcoming milestone

Link: http://seld.be/notes/the-road-to-monolog-2-0

SitePoint PHP Blog:
Logging with Monolog: From Devtools to Slack
Sep 02, 2015 @ 16:48:15

The SitePoint PHP blog has posted a tutorial showing you how to connect Monolog with Slack, a popular logging tool for PHP and a well-used communication (chat) service for development groups and projects. The basic idea is that, when something goes wrong, it's communicated directly to the chat channel versus just to a log somewhere for later analysis.

Logging is an important part of the app development/maintenance cycle. It’s not just about the data you log, but also about how you do it. In this article, we are going to explore the Monolog package and see how it can help us take advantage of our logs.

They start by helping you get Monolog installed in your project via Composer and how to create their "general" logger. He then explains the use of "handlers" in the Monolog system and how to add them to the logger instance. They also explain Monolog's "bubbling" of messages in a browser/error log example. Next they show how to integrate the SlackHandler into the logger, providing it with an access token, the channel to send to and a name to log in with. The article also shows how to format the message, giving it a bit nicer look than just the standard text error. Finally they touch on preprocessors that can add extra information to the log messages without having to touch every instance where it's used.

tagged: monolog slack integration message error realtime chat introduction

Link: http://www.sitepoint.com/logging-with-monolog-from-devtools-to-slack/

Three Devs & A Maybe:
Episode 70 - Composer, Monolog and Symfony2 with Jordi Boggiano
Jul 06, 2015 @ 13:37:24

The Three Devs & A Maybe podcast has posted a new episode (#70) featuring Composer and Jordi Boggiano, the creator and lead developer on the project.

This week we are joined by Jordi Boggiano, Composer (Dependency Manager for PHP) lead and Symfony2 core developer. We begin discussion with how he got into software development, touching on his involvement with Symfony2 before its official release. This topic leads us on to chat about why Composer was developed and how much it has grown in popularity. Jordi then discusses some of the changes he would make if he had the chance, along with what the Toran Proxy is. Finally, we discuss Composer performance and the popular Monolog package that he has developed.

You can listen to this latest episode either through the in-page player or by downloading the mp3 of the show. If you enjoy the episode, be sure to subscribe to their feed or follow them on Twitter to get the info on the latest episodes as they're released.

tagged: threedevsandamaybe podcast ep70 jordiboggiano composer monolog symfony2

Link: http://threedevsandamaybe.com/composer-monolog-and-symfony2-with-jordi-boggiano/

Stephan Hochdörfer:
Simple Logging Facade for PSR-3 loggers
Jun 17, 2015 @ 14:56:45

In his latest post Stephan Hochdörfer shares a library he's created to hopefully make it easier for developers to integrate PSR-3 compatible logging libraries into their code, a "logging facade" based on an idea from the Java world.

Lately I have seen more and more libraries picking up PSR-3 when it comes to logging. What a lot of libaries do wrong is that they depend on a concrete implementation of PSR-3, e.g. Mongolog instead of relying on the PSR-3 interface. From what I have seen this is because loggers get instantiated directly within the class. This is not a bad thing but it couples your code to a concrete implementation of PSR-3 which in turn means that there`s no interoperability.

The Java community solved the problem by creating a Simple Logging Facade library (SLF4) which I "ported" to PHP last week.

The library makes provides a simple static interface to setting the PSR-3 logger of your choice and fetching it from anywhere in your application. He includes an example of what the code would look like for a basic Monolog instance. He ends the post talking about this method for getting/setting the logger instance and how it compares to using other options like a dependency injection container or even just a manual call to a setter.

tagged: logger facade factory psr3 monolog example library

Link: https://blog.bitexpert.de/blog/simple-logging-facade-for-psr-3-loggers/


Trending Topics: