Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Symfony2 Essentials

You're reading from   Symfony2 Essentials

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784398767
Length 158 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Logging


To make our application more elegant while working in cron, we should implement logging to a file. Symfony2 supports some standard logs, through the so-called monolog component. To use this, we simply call for the logger service, and then we call the required method, either the info, err, debug, notice methods or the warn method, as in the following example:

$logger = $this->getContainer()->get('logger');
$logger->info('Info log message');

This log message will add to the default log (development or production) depending on the environment.

We need to change this a little bit, to allow the logs to be added to a separate file.

To do this, we need to define the channel and handler. When we create a channel, a separate logger service is created, and we can use it to log information here. Creating a simple channel is easy, as we just need to pass its name into the channel's array in the config file. After we add the channel, we need to add the handler, so that monolog would know...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image