Pimcore\Logger::log PHP Method

log() public static method

public static log ( $message, $level = "info", array $context = [] )
$message
$context array
    public static function log($message, $level = "info", $context = [])
    {
        if (!self::$enabled) {
            return;
        }
        // backward compatibility of level definitions
        // Zend_Logger compatibility
        $zendLoggerPsr3Mapping = self::getZendLoggerPsr3Mapping();
        if (array_key_exists($level, $zendLoggerPsr3Mapping)) {
            $level = $zendLoggerPsr3Mapping[$level];
        }
        if (!is_array($context)) {
            $context = [];
        }
        if (in_array($level, self::$priorities)) {
            $backtrace = debug_backtrace();
            if (!isset($backtrace[2])) {
                $call = ['class' => '', 'type' => '', 'function' => ''];
            } else {
                $call = $backtrace[2];
            }
            $call["line"] = $backtrace[1]["line"];
            if (is_object($message) || is_array($message)) {
                if (!$message instanceof \Exception) {
                    $message = print_r($message, true);
                }
            }
            $context["origin"] = $call["class"] . $call["type"] . $call["function"] . "() on line " . $call["line"];
            // add the memory consumption
            $memory = formatBytes(memory_get_usage(), 0);
            $memory = str_pad($memory, 6, " ", STR_PAD_LEFT);
            $context["memory"] = $memory;
            foreach (self::$logger as $logger) {
                if ($logger instanceof \Psr\Log\LoggerInterface) {
                    $logger->log($level, $message, $context);
                } else {
                    // Zend_Log backward compatibility
                    $zendLoggerPsr3ReverseMapping = array_flip($zendLoggerPsr3Mapping);
                    $zfCode = $zendLoggerPsr3ReverseMapping[$level];
                    $logger->log($message, $zfCode);
                }
            }
        }
    }

Usage Example

Example #1
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $link = Document\Hardlink::getById($this->getParam("id"));
             $this->setValuesToDocument($link);
             $link->setModificationDate(time());
             $link->setUserModification($this->getUser()->getId());
             if ($this->getParam("task") == "unpublish") {
                 $link->setPublished(false);
             }
             if ($this->getParam("task") == "publish") {
                 $link->setPublished(true);
             }
             // only save when publish or unpublish
             if ($this->getParam("task") == "publish" && $link->isAllowed("publish") || $this->getParam("task") == "unpublish" && $link->isAllowed("unpublish")) {
                 $link->save();
                 $this->_helper->json(["success" => true]);
             }
         }
     } catch (\Exception $e) {
         Logger::log($e);
         if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
             $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
         }
         throw $e;
     }
     $this->_helper->json(false);
 }
All Usage Examples Of Pimcore\Logger::log