Monolog - deSymfony unconference 2013
Upcoming SlideShare
Loading in...5
×
 

Monolog - deSymfony unconference 2013

on

  • 1,901 views

Monolog es un sistema de monitorización de aplicaciones escrito en PHP 5.3+ ...

Monolog es un sistema de monitorización de aplicaciones escrito en PHP 5.3+

Veremos cuales son las clases o tipos de clases principales que utiliza monolog y algunos ejemplos de como usarlos

Statistics

Views

Total Views
1,901
Views on SlideShare
1,524
Embed Views
377

Actions

Likes
0
Downloads
14
Comments
4

9 Embeds 377

http://librosweb.es 244
http://desarrolla2.com 58
https://twitter.com 57
http://desarrolla2.local 7
http://localhost 4
http://www.inoreader.com 2
http://fundafighter.local 2
http://karotz.eternalmind.fr 2
http://librosweb.dev 1
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hola Daniel, Muchas gracias :oP Saludos, Ricardo Pereira.
    Are you sure you want to
    Your message goes here
    Processing…
  • Acabo de verlo, si es un perro me muerde ...
    Are you sure you want to
    Your message goes here
    Processing…
  • Hola Ricardo

    He buscado en las opciones de slideshare y no encuentro como hacer la presentación 'descargable'.

    Un saludo!
    Are you sure you want to
    Your message goes here
    Processing…
  • Hola,

    Todas las presentaciones de deSymfony 2013 hasta el momento se pueden descargar, excepto esta...

    Respecto que no se pueda descargar la presentación, pero no me parece correcto hacerlo.

    Saludos, Ricardo Pereira.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Monolog - deSymfony unconference 2013 Monolog - deSymfony unconference 2013 Presentation Transcript

  • 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?