SlideShare a Scribd company logo
1 of 49
Download to read offline
Monolog
Unconference
deSymfony 2013
Monolog
Daniel González
@desarrolla2
Monolog
Monolog
Open Source
PHP5.3+
Inspired LogBook
Monolog
2,5 Years old
220 Forks
65 Contributors
Monolog
+200 Asserts
+ 70% Coverage
Monolog
170,000 installations / month
820,000 total installations
Monolog
It has not
dependencies
!!
Monolog
Created by a great
developer !!
Monolog
Monolog
Jordi Boggiano
@seldaek
Composer
Monolog
What for?
Monolog
$record = 'how are u??';
/**
* Log record
*
* @param string $record
*/
function log($record){
$filename = '/path/to/file.log';
file_put_contents($filename, (string) $record, FILE_APPEND);
}
Monolog
use MonologLogger;
use MonologHandlerStreamHandler;
// create a log channel
$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
// add records to the log
$logger->addRecord(Logger::DEBUG, 'Ha');
$logger->addWarning('He');
$logger->addError('Hi', array('user'=>'desarrolla2'));
Monolog
Logger
Monolog
$logger = new Logger('name');
Monolog
Handlers
Monolog
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
Monolog
const DEBUG = 100;
const INFO = 200;
const NOTICE = 250;
const WARNING = 300;
const ERROR = 400;
const CRITICAL = 500;
const ALERT = 550;
const EMERGENCY = 600;
Handler
Monolog
Logger
Handler
Handler
Logger
Monolog
Log to files and syslog
StreamHandler
RotatingFileHandler
SyslogHandler
Send alerts and emails
NativeMailHandler
SwiftMailerHandler
PushoverHandler
HipChatHandler
Log specific servers and
networked logging
SocketHandler
AmqpHandler
GelfHandler
CubeHandler
RavenHandler
ZendMonitorHandler
Monolog
Logging in development
FirePHPHandler
ChromePHPHandler
Log to databases
RedisHandler
MongoDBHandler
CouchDBHandler
DoctrineCouchDBHandler
Special Handlers
FingersCrossedHandler
BufferHandler
GroupHandler
NullHandler
TestHandler
Handler
Monolog
Logger Handler
Handler
Handler
GroupHandler
Processor
Processor
MailHandler
Monolog
Logger
Record
BufferHandler
Record
Record
Monolog
Logger
CrossFingerHandler
MailHandler
Record
Record
Record
Monolog
Records
Monolog
$logger->addWarning('He');
$logger->addError('Hi', array(
'user'=>'desarrolla2'
));
$logger->addRecord(Logger::DEBUG, 'Ha');
Monolog
$record = array(
'message' => (string) $message,
'context' => $context,
'level' => $level,
'level_name' => static::getLevelName($level),
'channel' => $this->name,
'datetime' => DateTime::createFromFormat('U.u', sprintf('%.6F', microtime
(true)), static::$timezone)->setTimezone(static::$timezone),
'extra' => array(),
);
Monolog
Processors
Monolog
$logger->pushProcessor(function ($record) {
$record['extra']['architecture'] = exec('uname -i');
return $record;
});
$handler = new StreamHandler('path/to/your.log', Logger::WARNING);
$handler->pushProcessor(function ($record) {
$record['extra']['load'] = sys_getloadavg();
return $record;
});
Monolog
Processors
IntrospectionProcessor
MemoryPeakUsageProcessor
MemoryUsageProcessor
ProcessIdProcessor
PsrLogMessageProcessor
UidProcessor
WebProcessor
Handler
Monolog
Logger
Handler
Handler
Processor
Processor
Processor
Processor
Logger
Monolog
Formatters
Monolog
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterLineFormatter;
$stream = new StreamHandler('path/to/your.log', Logger::WARNING);
$dateFormat = "Y n j, g:i a";
$output = "%datetime% > %level_name% > %message% %context% %extra%n";
$formatter = new LineFormatter($output, $dateFormat);
$stream->setFormatter($formatter);
Monolog
Formatters
ChromePHPFormatter
GelfMessageFormatter
JsonFormatter
LineFormatter
LogstashFormatter
NormalizerFormatter
WildfireFormatter
Handler
Monolog
Logger
Handler
Handler Processor
Processor
Processor
Processor
Formatter
Formatter
Monolog
Monolog
MYSQL
performance
debug
Monolog
$channel = 'mysql';
$logger = new Logger($channel);
$handler = new ChromePHPHandler(Logger::DEBUG, true);
$handler->pushProcessor(new MemoryUsageProcessor(true));
$handler->pushProcessor(function($record) {
$info = mysql_info();
$record['extra'] = array_merge(
$record['extra'], array(
'mysql_info' => $info,
)
);
return $record;
});
$logger->pushHandler($handler);
Monolog
for ($i = 1; $i <= 100; $i++) {
$sql = 'UPDATE table SET ...';
$logger->addRecord(Logger::DEBUG, $sql, array(
'id' => $i
));
}
Handler
Monolog
Logger
Processor
Processor
Monolog
Monolog
Monitoring
Errors
Monolog
class Controller
{
public function doSomething()
{
try {
// Important stuff ...
} catch (Exception $e) {
$this->container->get('logger.error')->error($e->getMessage(), array(
'user' => $this->getUser(),
'item' => $this->getItem(),
));
}
}
}
Monolog
$mongo = new MongoDBHandler(new Mongo("mongodb://localhost:27017"), "logs",
"errors", Logger::ERROR);
$mongo->pushProcessor(function ($record) {
$record['extra']['host'] = gethostname();
return $record;
}
);
$mongo->setFormatter(new JsonFormatter());
$mail = new NativeMailerHandler('admin@mycompany.com', 'Producction Error',
'noreply@mycompany.com', Logger::ERROR, true);
$mail->setFormatter(new MyCustomHTMLFormatter());
$logger->pushHandler($mongo);
$logger->pushHandler($mail);
Processor
Handler
Monolog
Logger
Formatter
Handler Formatter
Monolog
Dashboard
Monolog
And...
Symfony?
Monolog
Q?

More Related Content

What's hot

Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 
Desy powerpoint
Desy powerpointDesy powerpoint
Desy powerpoint
desyips
 

What's hot (15)

What is the difference between a good and a bad repository? (Forum PHP 2018)
What is the difference between a good and a bad repository? (Forum PHP 2018)What is the difference between a good and a bad repository? (Forum PHP 2018)
What is the difference between a good and a bad repository? (Forum PHP 2018)
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 
Laravel the right way
Laravel   the right wayLaravel   the right way
Laravel the right way
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
RegistryModClass
RegistryModClassRegistryModClass
RegistryModClass
 
LINEでWebアプリという可能性 - LIFF
LINEでWebアプリという可能性 - LIFFLINEでWebアプリという可能性 - LIFF
LINEでWebアプリという可能性 - LIFF
 
Gaelyk
GaelykGaelyk
Gaelyk
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classes
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Not Really PHP by the book
Not Really PHP by the bookNot Really PHP by the book
Not Really PHP by the book
 
Php
PhpPhp
Php
 
Routine per aprire documenti da vb6 [santi caltabiano].txt blocco note
Routine per aprire documenti da vb6 [santi caltabiano].txt   blocco noteRoutine per aprire documenti da vb6 [santi caltabiano].txt   blocco note
Routine per aprire documenti da vb6 [santi caltabiano].txt blocco note
 
Ok
OkOk
Ok
 
Desy powerpoint
Desy powerpointDesy powerpoint
Desy powerpoint
 

Similar to Monolog - deSymfony unconference 2013

I18n
I18nI18n
I18n
soon
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
jkumaranc
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
jkumaranc
 

Similar to Monolog - deSymfony unconference 2013 (20)

The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12
 
Logging
LoggingLogging
Logging
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
I18n
I18nI18n
I18n
 
Logging in Python for large applications
Logging in Python for large applicationsLogging in Python for large applications
Logging in Python for large applications
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
LOGBack and SLF4J
LOGBack and SLF4JLOGBack and SLF4J
LOGBack and SLF4J
 
Log4jxml ex
Log4jxml exLog4jxml ex
Log4jxml ex
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010The beautyandthebeast phpbat2010
The beautyandthebeast phpbat2010
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
How to save log4net into database
How to save log4net into databaseHow to save log4net into database
How to save log4net into database
 
Log4j in 8 slides
Log4j in 8 slidesLog4j in 8 slides
Log4j in 8 slides
 
Best practices for joomla extensions developers
Best practices for joomla extensions developersBest practices for joomla extensions developers
Best practices for joomla extensions developers
 

More from Daniel González Cerviño (6)

Refactoring with php storm
Refactoring with php stormRefactoring with php storm
Refactoring with php storm
 
Presentación del grupo PHPMad en el codemotion madrid 2014
Presentación del grupo PHPMad en el codemotion madrid 2014Presentación del grupo PHPMad en el codemotion madrid 2014
Presentación del grupo PHPMad en el codemotion madrid 2014
 
Codemotion Madrid 2013 - [PHP] desarrollo de extensiones en c c++
Codemotion Madrid 2013 - [PHP] desarrollo de extensiones en c c++Codemotion Madrid 2013 - [PHP] desarrollo de extensiones en c c++
Codemotion Madrid 2013 - [PHP] desarrollo de extensiones en c c++
 
Conquista la galaxia con GIT
Conquista la galaxia con GITConquista la galaxia con GIT
Conquista la galaxia con GIT
 
Varnish http cache
Varnish http cacheVarnish http cache
Varnish http cache
 
Introducción a TDD y PHPUnit
Introducción a TDD y PHPUnitIntroducción a TDD y PHPUnit
Introducción a TDD y PHPUnit
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Monolog - deSymfony unconference 2013