{"id":20534,"date":"2018-07-13T09:00:57","date_gmt":"2018-07-13T14:00:57","guid":{"rendered":"https:\/\/stackify.com\/?p=20534"},"modified":"2024-03-14T04:14:15","modified_gmt":"2024-03-14T04:14:15","slug":"php-monolog-tutorial","status":"publish","type":"post","link":"https:\/\/stackify.com\/php-monolog-tutorial\/","title":{"rendered":"PHP Monolog Tutorial: A Step by Step Guide"},"content":{"rendered":"<p>In application development or maintenance, logging is very important. It gives you the right amount of data that you need to help you monitor your application, logs, databases, code, and web services. Monolog is the existing standard logging library for PHP. It is most popular in PHP frameworks such as Laravel and Symfony, where it implements a common interface for logging libraries.<\/p>\n<p>This article talks about the step-by-step process of using PHP Monolog in your application.<\/p>\n<h3>Monolog\u00a0Installation<\/h3>\n<p>The basic way to use Monolog in PHP is to install the latest version of the Composer library<\/p>\n<p>in your project using this command. You can download it here: <a href=\"https:\/\/getcomposer.org\/\">https:\/\/getcomposer.org\/<\/a>.<\/p>\n<h4>Linux<\/h4>\n<pre class=\"prettyprint\">sudo php composer.phar require monolog\/monolog<\/pre>\n<h4>Windows<\/h4>\n<pre class=\"prettyprint\">composer require monolog\/monolog<\/pre>\n<p>In case you are not using composer, download the <strong>PSR-3 source code<\/strong> and install to your application.<\/p>\n<p>Make sure that you are using namespaces (to avoid a headache) so that you don\u2019t require a lot of files.<\/p>\n<h3><a id=\"post-20534-_qhay3tjgxmgl\"><\/a>Create loggers<\/h3>\n<p>First, when you create a logger, channel name should be included, so that you can distinguish your list of loggers.<\/p>\n<pre class=\"prettyprint\">$logger = new MonologLogger('channel-name');\n$app-&gt;container-&gt;logger = $logger;<\/pre>\n<p>In the example above, \u2018channel-name\u2019 should be included in every log entry. This way you can easily look up and filter the entries; createanother channel for each component. Examples of these channels might include \u2018database\u2019, \u2018security\u2019, \u2019business\u2019, and others.<\/p>\n<p>Loggers by nature don\u2019t know how to handle logs, but we also have what are called handlers that can handle logs.<\/p>\n<pre class=\"prettyprint\">require_once(DIR.'\/vendor\/autoload.php');\nuse MonologLogger;\nuse MonologHandlerStreamHandler;\n\n$logger = new Logger('channel-name');\n$logger-&gt;pushHandler(new StreamHandler(<strong>DIR<\/strong>.'\/app.log', Logger::DEBUG));\n$logger-&gt;info('This is a log! ^_^ ');\n$logger-&gt;warning('This is a log warning! ^_^ ');\n$logger-&gt;error('This is a log error! ^_^ ');\n\n<\/pre>\n<p class=\"c-mrkdwn__pre\" data-stringify-type=\"pre\">If you are using PHP 7.4 you will need to use this slightly modified code:<\/p>\n<pre class=\"c-mrkdwn__pre\" data-stringify-type=\"pre\">require __DIR__ . '\/vendor\/autoload.php';<\/pre>\n<pre class=\"c-mrkdwn__pre\" data-stringify-type=\"pre\">use Monolog\\Handler\\StreamHandler;<\/pre>\n<pre class=\"c-mrkdwn__pre\" data-stringify-type=\"pre\">use Monolog\\Logger;<\/pre>\n<pre class=\"c-mrkdwn__pre\" data-stringify-type=\"pre\">$logger = new Logger('channel-name');\n$logger-&gt;pushHandler(new StreamHandler(__DIR__ . '\/app.log', Logger::DEBUG));<\/pre>\n<p>Handlers can be pushed as many as you need to a Logger instance. These types of handler will decide the kind of logs to be handled. In the example provided above, StreamHandler, reports entries in the file system app.log.<\/p>\n<h3><a id=\"post-20534-_n9w3y38gz7r\"><\/a>Intensity level<\/h3>\n<p>An intensity level is added to each log entry, along with channel name to allow you to check and filter the entries.<\/p>\n<p>As illustrated in <strong>RFC 5424<\/strong> which describes the syslog protocol, the following levels of intensity are applied in Monolog.<\/p>\n<ul>\n<li><strong>DEBUG<\/strong>: Detailed debugging information.<\/li>\n<li><strong>INFO<\/strong>: Handles normal events. Example: SQL logs<\/li>\n<li><strong>NOTICE<\/strong>: Handles normal events, but with more important events<\/li>\n<li><strong>WARNING<\/strong>: Warning status, where you should take an action before it will become an error.<\/li>\n<li><strong>ERROR<\/strong>: Error status, where something is wrong and needs your immediate action<\/li>\n<li><strong>CRITICAL<\/strong>: Critical status. Example: System component is not available<\/li>\n<li><strong>ALERT<\/strong>: Immediate action should be exercised. This should trigger some alerts and wake you up during night time.<\/li>\n<li><strong>EMERGENCY<\/strong>: It is used when the system is unusable.<\/li>\n<\/ul>\n<p>An info log entry of a channel called \u2018channel-name\u2019, for example, looks like this:<\/p>\n<pre class=\"prettyprint\">[2018-07-05 11:10:35] channel-name.INFO: This is a log entry!\n[2018-07-09 02:58:27] channel-name.WARNING: This is a log warning! ^_^ [] []\n[2018-07-09 02:58:27] channel-name.ERROR: This is a log error! ^_^ [] []<\/pre>\n<p>Monolog stores one add for each type of intensity level, likely, error, notice, warning, info, and so on.<\/p>\n<h3><a id=\"post-20534-_z1hm302qzhep\"><\/a>PHP example code<\/h3>\n<p>The following code is the basic sample setup to log to a file and to firephp on the Debug level.<\/p>\n<pre class=\"prettyprint\">require_once(DIR.'\/vendor\/autoload.php');\nuse MonologLogger;\nuse MonologHandlerStreamHandler;\nuse MonologHandlerFirePHPHandler;\n\n$logger = new Logger('logger');\n$logger-&gt;pushHandler(new StreamHandler(<strong>DIR<\/strong>.'\/test_app.log', Logger::DEBUG));\n$logger-&gt;pushHandler(new FirePHPHandler());\n$logger-&gt;error('Logger is now Ready');<\/pre>\n<p>In the sample, it has two handlers in the stack to provide records in two different ways. FirePHPHandlers are described as it is joined on top of the stack. This permits you to tentatively append a logger with bubbling disabled, if you want to revoke other configured loggers.<\/p>\n<h3><a id=\"post-20534-_iq6qod3kbzk6\"><\/a>Handler order<\/h3>\n<p>When you add a log entry handler to the logger instance, it matters which order you push the handler. When a log entry is added, it will directly go to the handler stack. When a handler&#8217;s constructor is set to false, it stops traversing through the handler stack.<\/p>\n<pre class=\"prettyprint\">require_once(DIR.'\/vendor\/autoload.php');\nuse MonologLogger;\nuse MonologHandlerStreamHandler;\nuse MonologHandlerSwiftMailerHandler;\n\n\/\/ Create the Transport\n$transporter = new Swift_SmtpTransport('smtp.example.com', 465, 'ssl');\n$transporter-&gt;setUsername('user@example.com');\n$transporter-&gt;setPassword('123456');\n\n\/\/ Create the Mailer using your created Transport\n$mailer = new Swift_Mailer($transporter);\n\n\/\/ Create a message\n$message = (new Swift_Message('A CRITICAL log was added'));\n$message-&gt;setFrom(['example-FROM@example.com' =&gt; 'Someone FROM']);\n$message-&gt;setTo(['someone-TO@example.com' =&gt; 'SomeoneTO']);\n\n$logger = new Logger('default');\n$logger-&gt;pushHandler(new StreamHandler(<strong>DIR<\/strong>.'\/test.log', Logger::INFO));\n$logger-&gt;pushHandler(new SwiftMailerHandler($mailer, $message, Logger::CRITICAL, false));\n$logger-&gt;addCritical('Hey, a critical log entry!');<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-21289\" src=\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/word-image-44.png\" alt=\"log\" width=\"535\" height=\"316\" \/><\/p>\n<p>First, you need to install SwiftMailer (composer require swiftmailer\/swiftmailer) to be able to use the SwiftMailerHandler. For you to be able to send emails, you need to use Swift_SmtpTransport, Swift_Message, and Swift_Mailer to join $mailer and $message to the SwiftMailerHandler instance.<\/p>\n<p>When you examine the last parameter of SwiftMailer&#8217;s constructor, it returns false for the last parameter, called $bubble parameter. Technically, by default, it returns true, but when set to false it means that it stops traversing the handler stack. This is a technique in which making the StreamHandler that is located at the bottom of the stack; it never store logs in the file system if SwiftMailerHandler manages the entry.<\/p>\n<h3><a id=\"post-20534-_9e2jaem4t1yx\"><\/a>Array<\/h3>\n<p>Array passing is as simple as the following code:<\/p>\n<pre class=\"prettyprint\">$username = 'jmendez';\n$logger-&gt;addInfo('User registered', ['username' =&gt; $username]);<\/pre>\n<p>This is a way to pass an array to the add method such as addDebug, addInfo, etc.<\/p>\n<h3><a id=\"post-20534-_vxw2m084aicc\"><\/a>Processors<\/h3>\n<p>In Monolog, you can create your own processor even though it provides a lot of processors by default. Processors are used to include information in log entries such as client&#8217;s IP and browser, and others. Here&#8217;s a sample code snippet:<\/p>\n<pre class=\"prettyprint\">$logger = new Logger('default');\n$logger-&gt;pushHandler(new StreamHandler(<strong>DIR<\/strong>.'\/test.log', Logger::INFO));\n$logger-&gt;pushProcessor(function ($entry) {\n    $entry['extra']['data'] = 'Hello world!';\n    return $entry;\n});\n$logger-&gt;addInfo('User registered', ['username'=&gt;'jmendez']);<\/pre>\n<p>The sample above would simply store the log entry in this format<\/p>\n<pre class=\"prettyprint\">[2018-07-05 11:18:29] default.INFO: User registered {'username':'jmendez'} {\"data\":\"Hello world!\"}<\/pre>\n<p>You can also use the built-in processor that Monolog provides. You directly use the class and push an instance using the pushProcessor method. Here is sample code using pushProcessor.<\/p>\n<pre class=\"prettyprint\">use MonologLogger;\nuse MonologHandlerStreamHandler;\nuse MonologProcessorWebProcessor;\n\n$logger = new Logger('default');\n$logger-&gt;pushHandler(new StreamHandler(<strong>DIR<\/strong>.'\/test.log', Logger::INFO));\n$logger-&gt;pushProcessor(new WebProcessor());\n$logger-&gt;addInfo('User registered', ['username'=&gt;'jmendez']);<\/pre>\n<h3><a id=\"post-20534-_6lvm3a03hq4\"><\/a>Formatters<\/h3>\n<p>In Monolog, there are a lot of formatters that can be used. You can find some built-in formatters <a href=\"https:\/\/github.com\/Seldaek\/monolog\/blob\/master\/doc\/02-handlers-formatters-processors.md#processors\">here<\/a>. You can also customize the format of the logs that are written in files, emails, databases, and other handlers.<\/p>\n<pre class=\"prettyprint\">$record['formatted']<\/pre>\n<p>is the most common way to use a handler with a value to be directly put into the log device. Formatters can be customized, so you can write your own. Here is a simple configuration for a built-in formatter class that formats the log sent by email, which can be understandable by everyone who will be using your system.<\/p>\n<pre class=\"prettyprint\">use MonologLogger;\nuse MonologHandlerSwiftMailerHandler;\nuse MonologFormatterHtmlFormatter;\n\n\/\/ Create the Transport\n$transporter = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');\n$transporter-&gt;setUsername('user@example.com');\n$transporter-&gt;setPassword(123456);\n\n\/\/ Create the Mailer using your created Transport\n$mailer = new Swift_Mailer($transporter);\n\n\/\/ Create a message\n$message = (new Swift_Message('A CRITICAL log was added'));\n$message-&gt;setFrom(['fromuser@example.com' =&gt; 'From User']);\n$message-&gt;setTo(['touser@example.com' =&gt; 'To User']);\n$message-&gt;setContentType(\"text\/html\");\n\n$logger = new Logger('default');\n$mailerHandler = new SwiftMailerHandler($mailer, $message, Logger::CRITICAL);\n$mailerHandler-&gt;setFormatter(new HtmlFormatter());\n$logger-&gt;pushHandler($mailerHandler);\n$logger-&gt;addCritical('This is a critical message!');<\/pre>\n<p>In the example, I am using an HtmlFormatter object to the SwiftMailer and then define the $message and set content type to text\/html. In the email, this would look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-21290\" src=\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/word-image-45.png\" alt=\"critical log\" width=\"530\" height=\"532\" \/><\/p>\n<p>Most of the third-party handlers, formatters and processors can be found in the <a href=\"https:\/\/github.com\/Seldaek\/monolog\/wiki\/Third-Party-Packages\">wiki<\/a>. You can always write your own if you want.! \ud83d\ude09<\/p>\n<h3><a id=\"post-20534-_9e2jaem4t1yx\"><\/a>Send your logs to Retrace<\/h3>\n<p>Logs are crucial part in every application, it gives you information about your entire application and check whatever blindspot in your application. One of the advantage in using Retrace in your application is that it can support centralized logging. Centralized logging gives you the complete view of your environment. In manual PHP application, you go through the process of finding and guessing some of the errors and logs in your system.<\/p>\n<p>Below is an example of log monitoring work in <a href=\"https:\/\/stackify.com\/retrace\/\">Retrace<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-21291\" src=\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/word-image-46.png\" alt=\"image\" width=\"1869\" height=\"717\" \/><\/p>\n<h3>More information<\/h3>\n<p>See the following articles about PHP logging:<\/p>\n<ul>\n<li><a title=\"18 PHP Tools for Developers of all Levels\" href=\"https:\/\/stackify.com\/php-tools-developers\/\">18\u00a0<em>PHP<\/em>\u00a0Tools for Developers of all Levels<\/a><\/li>\n<li><a title=\"Errors and Logs: Configure PHP Applications\" href=\"https:\/\/support.stackify.com\/errors-and-logs-configure-php-applications\/?_ga=2.55879403.1186450916.1531420228-602583965.1506728755\">Errors and Logs: Configure\u00a0<em>PHP<\/em>\u00a0Applications<\/a><\/li>\n<\/ul>\n<h3><a id=\"post-20530-_1d1e617dgvno\"><\/a>Summary<\/h3>\n<p>Monolog is integrated into most of the popular frameworks like Laravel, Symfony, Slim, and many others, as of today, Monolog is one of the excellent tools available for logging libraries. I hope this article guides you, and helps you in logging your PHP applications.<\/p>\n<p>Retrace gives convenience in monitoring logs and troubleshoot problems quickly.<\/p>\n<p><a href=\"https:\/\/s1.stackify.com\/account\/createclient\">Sign up for a free trial<\/a> of Retrace and try it today!<\/p>\n<h3><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>In application development or maintenance, logging is very important. It gives you the right amount of data that you need to help you monitor your application, logs, databases, code, and web services. Monolog is the existing standard logging library for PHP. It is most popular in PHP frameworks such as Laravel and Symfony, where it [&hellip;]<\/p>\n","protected":false},"author":39,"featured_media":37567,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7],"tags":[26,39],"class_list":["post-20534","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-logging","tag-php"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v25.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Monolog Tutorial: A Step by Step Guide - Stackify<\/title>\n<meta name=\"description\" content=\"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/stackify.com\/php-monolog-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Monolog Tutorial: A Step by Step Guide - Stackify\" \/>\n<meta property=\"og:description\" content=\"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/stackify.com\/php-monolog-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Stackify\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Stackify\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-13T14:00:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-14T04:14:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"881\" \/>\n\t<meta property=\"og:image:height\" content=\"441\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Juliet Mendez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@stackify\" \/>\n<meta name=\"twitter:site\" content=\"@stackify\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Juliet Mendez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/\"},\"author\":{\"name\":\"Juliet Mendez\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/b3b39ab658fc4593a581e9cbbb37d1fe\"},\"headline\":\"PHP Monolog Tutorial: A Step by Step Guide\",\"datePublished\":\"2018-07-13T14:00:57+00:00\",\"dateModified\":\"2024-03-14T04:14:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/\"},\"wordCount\":1125,\"publisher\":{\"@id\":\"https:\/\/stackify.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg\",\"keywords\":[\"logging\",\"PHP\"],\"articleSection\":[\"Developer Tips, Tricks &amp; Resources\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/\",\"url\":\"https:\/\/stackify.com\/php-monolog-tutorial\/\",\"name\":\"PHP Monolog Tutorial: A Step by Step Guide - Stackify\",\"isPartOf\":{\"@id\":\"https:\/\/stackify.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg\",\"datePublished\":\"2018-07-13T14:00:57+00:00\",\"dateModified\":\"2024-03-14T04:14:15+00:00\",\"description\":\"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/stackify.com\/php-monolog-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage\",\"url\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg\",\"contentUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg\",\"width\":881,\"height\":441},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/stackify.com\/#website\",\"url\":\"https:\/\/stackify.com\/\",\"name\":\"Stackify\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/stackify.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/stackify.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/stackify.com\/#organization\",\"name\":\"Stackify\",\"url\":\"https:\/\/stackify.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png\",\"contentUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png\",\"width\":1377,\"height\":430,\"caption\":\"Stackify\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Stackify\/\",\"https:\/\/x.com\/stackify\",\"https:\/\/www.instagram.com\/stackify\/\",\"https:\/\/www.linkedin.com\/company\/2596184\",\"https:\/\/www.youtube.com\/stackify\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/b3b39ab658fc4593a581e9cbbb37d1fe\",\"name\":\"Juliet Mendez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4f9a8bb14708a86f6bd52bb3c0577c6c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4f9a8bb14708a86f6bd52bb3c0577c6c?s=96&d=mm&r=g\",\"caption\":\"Juliet Mendez\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP Monolog Tutorial: A Step by Step Guide - Stackify","description":"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/stackify.com\/php-monolog-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"PHP Monolog Tutorial: A Step by Step Guide - Stackify","og_description":"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.","og_url":"https:\/\/stackify.com\/php-monolog-tutorial\/","og_site_name":"Stackify","article_publisher":"https:\/\/www.facebook.com\/Stackify\/","article_published_time":"2018-07-13T14:00:57+00:00","article_modified_time":"2024-03-14T04:14:15+00:00","og_image":[{"width":881,"height":441,"url":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg","type":"image\/jpeg"}],"author":"Juliet Mendez","twitter_card":"summary_large_image","twitter_creator":"@stackify","twitter_site":"@stackify","twitter_misc":{"Written by":"Juliet Mendez","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/stackify.com\/php-monolog-tutorial\/#article","isPartOf":{"@id":"https:\/\/stackify.com\/php-monolog-tutorial\/"},"author":{"name":"Juliet Mendez","@id":"https:\/\/stackify.com\/#\/schema\/person\/b3b39ab658fc4593a581e9cbbb37d1fe"},"headline":"PHP Monolog Tutorial: A Step by Step Guide","datePublished":"2018-07-13T14:00:57+00:00","dateModified":"2024-03-14T04:14:15+00:00","mainEntityOfPage":{"@id":"https:\/\/stackify.com\/php-monolog-tutorial\/"},"wordCount":1125,"publisher":{"@id":"https:\/\/stackify.com\/#organization"},"image":{"@id":"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg","keywords":["logging","PHP"],"articleSection":["Developer Tips, Tricks &amp; Resources"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/stackify.com\/php-monolog-tutorial\/","url":"https:\/\/stackify.com\/php-monolog-tutorial\/","name":"PHP Monolog Tutorial: A Step by Step Guide - Stackify","isPartOf":{"@id":"https:\/\/stackify.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg","datePublished":"2018-07-13T14:00:57+00:00","dateModified":"2024-03-14T04:14:15+00:00","description":"Monolog is the existing standard logging library for PHP. Get a step-by-step process of using PHP Monolog in your application.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/stackify.com\/php-monolog-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/php-monolog-tutorial\/#primaryimage","url":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg","contentUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/07\/PHP-Monolog-881x441-1.jpg","width":881,"height":441},{"@type":"WebSite","@id":"https:\/\/stackify.com\/#website","url":"https:\/\/stackify.com\/","name":"Stackify","description":"","publisher":{"@id":"https:\/\/stackify.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/stackify.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/stackify.com\/#organization","name":"Stackify","url":"https:\/\/stackify.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/#\/schema\/logo\/image\/","url":"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png","contentUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png","width":1377,"height":430,"caption":"Stackify"},"image":{"@id":"https:\/\/stackify.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Stackify\/","https:\/\/x.com\/stackify","https:\/\/www.instagram.com\/stackify\/","https:\/\/www.linkedin.com\/company\/2596184","https:\/\/www.youtube.com\/stackify"]},{"@type":"Person","@id":"https:\/\/stackify.com\/#\/schema\/person\/b3b39ab658fc4593a581e9cbbb37d1fe","name":"Juliet Mendez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4f9a8bb14708a86f6bd52bb3c0577c6c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4f9a8bb14708a86f6bd52bb3c0577c6c?s=96&d=mm&r=g","caption":"Juliet Mendez"}}]}},"_links":{"self":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts\/20534"}],"collection":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/comments?post=20534"}],"version-history":[{"count":2,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts\/20534\/revisions"}],"predecessor-version":[{"id":43411,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts\/20534\/revisions\/43411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/media\/37567"}],"wp:attachment":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/media?parent=20534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/categories?post=20534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/tags?post=20534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}