The Wayback Machine - https://web.archive.org/web/20191113010725/http://php.sys-con.com:80/node/3199825

Welcome!

PHP Authors: Liz McMillan, Carmen Gonzalez, Hovhannes Avoyan, Lori MacVittie, Trevor Parsons

Related Topics: @DevOpsSummit, PHP

@DevOpsSummit: Blog Post

Logging From PHP Web Frameworks Like Laravel | @DevOpsSummit [#DevOps]

Laravel is a relatively new MVC web framework for PHP that was released in 2012

So what is Laravel?

Laravel is a relatively new MVC web framework for PHP that was released in 2012. It’s also the most popular PHP project on Github at the time of this post. Like many web frameworks, Laravel boasts an easy learning-curve to get an app up and running. This was certainly the case when I used it.

While this post is focusing on logging in Laravel, its applicable to other php web frameworks, like Symfony2 and Aura to name a few. It’s worth noting that Laravel actually has several Symfony dependencies but the two can be used independently to build a web app.

When it comes to logging, each of these web frameworks have followed the PSR-3 logging standard interface.

logging-from-php-web-frameworksThis helpful standard is also implemented by Monolog, a popular PHP logging library that is inspired by Pythons Logbook library.
Thanks to this, the frameworks actually come with Monolog out of the box, making it very easy to switch between them with minimal effect to your logging configurations, should you need to migrate your app.
Setting up with Monolog is just as simple.
In the case of Laravel, we can find the default logging configuration at this location in our projects root directory:
app/start/global.php
The default config writes to a file in the projects log folder located below in the project directory:

storage/logs

Thanks to one of our users and contributors, Rob Kaufmann, Monolog ships with built-in Logentries support, so we need only add 2 lines to

global.php

to start sending logs to Logentries.

This snippet below shows what we need to add to configure our Laravel config to point Monolog towards Logentries:

$logentriesHandler = new Monolog\Handler\LogEntriesHandler('LOG_TOKEN');
Log::getMonolog()->pushHandler($logentriesHandler);

The LogEntriesHandler has a single required parameter which is the UUID token for a log on Logentries, this allows the library to send logs to a specified log in a Logentries account.

To obtain a token, simply follow these steps:

1. Create A Log Destination

First, we need a Logentries Account, which you can get for free. Once we have a Logentries account, we’ll need a destination log in order to store the entries sent from within our Laravel app. In the Logentries UI, create a new log by clicking the Create Log button. If you already have a Host set up, you can add the log to the existing Host by click on the Host in the Web UI and then “Add new log”  as shown below:

add_new_log
2. Click Manual Configuration button from the list of options.

manual_configuration

3. Give the new log a name of your choice, and then select “Token TCP”:

 

Configure_and_upload_Token_TCP
4. Click the Register New Log button.

A token will be displayed in green. Copy this token and insert it into your global.php resulting in a config snippet similar to this:

$logentriesHandler = new Monolog\Handler\LogEntriesHandler('COPIED_TOKEN');
Log::getMonolog()->pushHandler($logentriesHandler);

Now, any log statements written by your Laravel app will now be forwarded to Logentries, it doesn’t get any easier than that.

More Stories By Trevor Parsons

Trevor Parsons is Chief Scientist and Co-founder of Logentries. Trevor has over 10 years experience in enterprise software and, in particular, has specialized in developing enterprise monitoring and performance tools for distributed systems. He is also a research fellow at the Performance Engineering Lab Research Group and was formerly a Scientist at the IBM Center for Advanced Studies. Trevor holds a PhD from University College Dublin, Ireland.

IoT & Smart Cities Stories
Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D; departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.