2. Presenter: Satheeskumar A, Mindfire Solutions
About me
➢ Zend Certified Engineer (ZCE)
➢ Oracle Certified Mysql Professional (OCP – MYSQL)
➢ 10 gen certified Mongodb professional
➢ Microsoft Certified HTML5 professional
➢ Accrediated certified Scrum Master
Skills: PHP, Mysql, Symfony2, CodeIgniter, SVN, GIT,
Doctrine, Propel ...
Connect me:
Facebook: https://www.facebook.com/satheeskumar.ashokkumar/
Twitter: https://twitter.com/sathees1kumar
Linked in: in.linkedin.com/in/satheeskumara/
Google Plus: https://plus.google.com/+satheeskumara
Contact me:
E-mail: satheeskumara@mindfiresolutions.com / Sathees1kumar@gmail.com
Skype: mfsi_satheesk
3. Presenter: Satheeskumar A, Mindfire Solutions
Agenda
What is Logging
History of logging
Need of Logging
Current Conventions
Use of Monolog
Components of Monolog
Different Types of Handlers
Types of Formatters
Tips and Tricks
Sample Code
4. Take Away
“To know the best method of logging data of different
contexts for specific environments such as test/dev
and production”
Presenter: Satheeskumar A, Mindfire Solutions
5. Logging
Presenter: Satheeskumar A, Mindfire Solutions
The process of using a computer to collect data through
sensors/listeners/events.
Analyze the data and save and output the results of the
collection and analysis.
Data logging also implies the control of how the computer
collects and analyzes the data.
6. History of Logging
Presenter: Satheeskumar A, Mindfire Solutions
Even with use of computers there was a real need to measure the
overall performance of any reasearch
Early 1980's there was a Instrument called VELA (virtual laboratory)
used for data harvesting
Late 1980's, A device was invented to collect information through
sensors
Later then data logging/harvesting has been used widely in all
applications/reasearches/products.
7. Need of Logging
Presenter: Satheeskumar A, Mindfire Solutions
Track Users activity/Movement
Transaction Logging
Track user errors
System level failures/warnings
Research Data collection and Interpretation
9. Current Conventions - Apache/PHP
Presenter: Satheeskumar A, Mindfire Solutions
<VirtualHost *:80>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
10. Monolog Enters Here...
Presenter: Satheeskumar A, Mindfire Solutions
Monolog is a PHP library that support different levels of
logging for PHP Applications and depends on PSR.
Inspired by Python Logbook library
Provides stack of handlers
More Powerful than conventional way of logging in
applications
11. What's different ?
Presenter: Satheeskumar A, Mindfire Solutions
●
Monolog sends your logs to files, sockets, inboxes, databases
and various web services.
●
Channel based approach
●
Different stack of handlers for specific channels
●
Pile up handler stack based on severity.
●
Format Interpretation depending on severity and channel
●
Prevents Bubbling when severity is reached
13. Components that make up
Presenter: Satheeskumar A, Mindfire Solutions
●
Handlers
●
Formatters
●
Processors
●
Dependent packages like send_mail / FirePHP/
Chrome PHP etc..
14. Handlers
Presenter: Satheeskumar A, Mindfire Solutions
●
Each logger instance will have a stack of handlers.
●
If no handlers are pushed to the stack, stream handler will handled as the
default.
●
The last pushed handler will be treated first.
●
Other handlers are bubbled up based on severity
●
Bubbling can be stopped at any level. Handler instances can be shared
between multiple channels.
●
Support to write to Database and cloud services
15. Formatters
Presenter: Satheeskumar A, Mindfire Solutions
●
Each handler has a default format.
●
Custom Formatter instance can be assigned to any
Handler.
●
Formatters can be shared between different handlers
●
Formatters can be different for different channels
●
Line Formatter is the default formatter.
16. Processors
Presenter: Satheeskumar A, Mindfire Solutions
●
Processors to include more details before the handler
renders the log message.
●
Can be used to nail down the issue
●
Used to measure the memory usage
●
Introspection of running processess.
17. Advantages
Presenter: Satheeskumar A, Mindfire Solutions
●
Option to have different channel for different module
●
Custom detailing
●
Different handlers for different development
●
Thorough participation in different stages of lifecycle
●
Open for third party integration
●
Readable and Beautiful Layered message
18. Monolog in Development Env
Presenter: Satheeskumar A, Mindfire Solutions
●
Use of FirePHPHandler and ChromePHPHandler
●
FirePHPFormatting can be used to format the log messages
●
Prevention of bubbling from writing to database
19. Monolog in Production Env
Presenter: Satheeskumar A, Mindfire Solutions
●
Rotatelog handler rotates log
●
Send Beautiful error messages via HTML mails
●
Write the log messages to any Database mysql, mongo, couch.
●
Support with ORM packages like Doctrine etc..
●
Can be integrated to cloud services like Loggly
●
Keeps your log messages distinct for different modular
functionality
20. Lets dirty our hands with code
Presenter: Satheeskumar A, Mindfire Solutions
$log = new Logger('app');
$log->pushHandler( new StreamHandler(__DIR__
. '/logs/error.log', Logger::NOTICE, false));
$log->addNotice('this is a notice');
$log->addNotice('this is an error');
21. Sample Code in GIT
Presenter: Satheeskumar A, Mindfire Solutions
https://github.com/sathees1kumar/monolog
Feel free to fork and play :)
23. References
Presenter: Satheeskumar A, Mindfire Solutions
The only link which is more than enough to get started with,
https://github.com/Seldaek/monolog