SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"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 ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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, ...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Monolog - deSymfony unconference 2013