Your SlideShare is downloading. ×
0
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Monolog - deSymfony unconference 2013
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Monolog - deSymfony unconference 2013

2,216

Published on

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

4 Comments
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
2,216
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
21
Comments
4
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Monolog Unconference deSymfony 2013
  • 2. Monolog Daniel González @desarrolla2
  • 3. Monolog
  • 4. Monolog Open Source PHP5.3+ Inspired LogBook
  • 5. Monolog 2,5 Years old 220 Forks 65 Contributors
  • 6. Monolog +200 Asserts + 70% Coverage
  • 7. Monolog 170,000 installations / month 820,000 total installations
  • 8. Monolog It has not dependencies !!
  • 9. Monolog Created by a great developer !!
  • 10. Monolog
  • 11. Monolog Jordi Boggiano @seldaek Composer
  • 12. Monolog What for?
  • 13. 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); }
  • 14. 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'));
  • 15. Monolog Logger
  • 16. Monolog $logger = new Logger('name');
  • 17. Monolog Handlers
  • 18. Monolog $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
  • 19. 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;
  • 20. Handler Monolog Logger Handler Handler Logger
  • 21. 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
  • 22. Monolog Logging in development FirePHPHandler ChromePHPHandler Log to databases RedisHandler MongoDBHandler CouchDBHandler DoctrineCouchDBHandler Special Handlers FingersCrossedHandler BufferHandler GroupHandler NullHandler TestHandler
  • 23. Handler Monolog Logger Handler Handler Handler GroupHandler Processor Processor
  • 24. MailHandler Monolog Logger Record BufferHandler Record Record
  • 25. Monolog Logger CrossFingerHandler MailHandler Record Record Record
  • 26. Monolog Records
  • 27. Monolog $logger->addWarning('He'); $logger->addError('Hi', array( 'user'=>'desarrolla2' )); $logger->addRecord(Logger::DEBUG, 'Ha');
  • 28. 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(), );
  • 29. Monolog Processors
  • 30. 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; });
  • 31. Monolog Processors IntrospectionProcessor MemoryPeakUsageProcessor MemoryUsageProcessor ProcessIdProcessor PsrLogMessageProcessor UidProcessor WebProcessor
  • 32. Handler Monolog Logger Handler Handler Processor Processor Processor Processor Logger
  • 33. Monolog Formatters
  • 34. 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);
  • 35. Monolog Formatters ChromePHPFormatter GelfMessageFormatter JsonFormatter LineFormatter LogstashFormatter NormalizerFormatter WildfireFormatter
  • 36. Handler Monolog Logger Handler Handler Processor Processor Processor Processor Formatter Formatter
  • 37. Monolog
  • 38. Monolog MYSQL performance debug
  • 39. 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);
  • 40. Monolog for ($i = 1; $i <= 100; $i++) { $sql = 'UPDATE table SET ...'; $logger->addRecord(Logger::DEBUG, $sql, array( 'id' => $i )); }
  • 41. Handler Monolog Logger Processor Processor
  • 42. Monolog
  • 43. Monolog Monitoring Errors
  • 44. 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(), )); } } }
  • 45. 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);
  • 46. Processor Handler Monolog Logger Formatter Handler Formatter
  • 47. Monolog Dashboard
  • 48. Monolog And... Symfony?
  • 49. Monolog Q?

×