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/t...
Monolog
use MonologLogger;
use MonologHandlerStreamHandler;
// create a log channel
$logger = new Logger('name');
$logger-...
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 = ...
Handler
Monolog
Logger
Handler
Handler
Logger
Monolog
Log to files and syslog
StreamHandler
RotatingFileHandler
SyslogHandler
Send alerts and emails
NativeMailHandler
S...
Monolog
Logging in development
FirePHPHandler
ChromePHPHandler
Log to databases
RedisHandler
MongoDBHandler
CouchDBHandler...
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::DEB...
Monolog
$record = array(
'message' => (string) $message,
'context' => $context,
'level' => $level,
'level_name' => static:...
Monolog
Processors
Monolog
$logger->pushProcessor(function ($record) {
$record['extra']['architecture'] = exec('uname -i');
return $record;
}...
Monolog
Processors
IntrospectionProcessor
MemoryPeakUsageProcessor
MemoryUsageProcessor
ProcessIdProcessor
PsrLogMessagePr...
Handler
Monolog
Logger
Handler
Handler
Processor
Processor
Processor
Processor
Logger
Monolog
Formatters
Monolog
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterLineFormatter;
$stream = new StreamHandler...
Monolog
Formatters
ChromePHPFormatter
GelfMessageFormatter
JsonFormatter
LineFormatter
LogstashFormatter
NormalizerFormatt...
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...
Monolog
for ($i = 1; $i <= 100; $i++) {
$sql = 'UPDATE table SET ...';
$logger->addRecord(Logger::DEBUG, $sql, array(
'id'...
Handler
Monolog
Logger
Processor
Processor
Monolog
Monolog
Monitoring
Errors
Monolog
class Controller
{
public function doSomething()
{
try {
// Important stuff ...
} catch (Exception $e) {
$this->co...
Monolog
$mongo = new MongoDBHandler(new Mongo("mongodb://localhost:27017"), "logs",
"errors", Logger::ERROR);
$mongo->push...
Processor
Handler
Monolog
Logger
Formatter
Handler Formatter
Monolog
Dashboard
Monolog
And...
Symfony?
Monolog
Q?
Upcoming SlideShare
Loading in...5
×

Monolog - deSymfony unconference 2013

2,319

Published on

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,319
On Slideshare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
21
Comments
4
Likes
0
Embeds 0
No embeds

No notes for slide

Monolog - deSymfony unconference 2013

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

    Clipping is a handy way to collect important slides you want to go back to later.

×