【问题标题】:What is the meaning of null in Mage log (magento)?Mage log(magento)中的null是什么意思?
【发布时间】:2014-07-05 19:45:44
【问题描述】:

为了创建 Magento 日志,可以编写类似的东西

 Mage::log('Server Side Validation kicked in for Year for '.$currentYearType);

但是如果我要在单独的文件中添加日志,我会这样做吗

Mage::log('Server Side Validation kicked in for Year for ' ,null,'serversidevalidation.log');

如果我错了,请纠正我。

如果是这样,中间的null有什么用? 此外,该文件是否需要事先存在,或者我认为它是由系统在需要时创建的。我对吗?另外,它会包括时间戳吗?

【问题讨论】:

    标签: magento logging


    【解决方案1】:

    转到app/Mage.php

    第 785 行

    public static function log($message, $level = null, $file = '', $forceLog = false) 
    

    你可以看到第二个参数是level

    $level  = is_null($level) ? Zend_Log::DEBUG : $level;
    

    lib\Zend\log.php

    const EMERG   = 0;  // Emergency: system is unusable
    const ALERT   = 1;  // Alert: action must be taken immediately
    const CRIT    = 2;  // Critical: critical conditions
    const ERR     = 3;  // Error: error conditions
    const WARN    = 4;  // Warning: warning conditions
    const NOTICE  = 5;  // Notice: normal but significant condition
    const INFO    = 6;  // Informational: informational messages
    const DEBUG   = 7;  // Debug: debug messages
    

    如果你这个代码Mage::log('test', 1);

    然后你会在日志文件中得到这样的输出

    2014-05-17T12:21:51+00:00 ALERT (1): test
    

    是的,文件是系统调用时自动创建的

    系统在调用时包含时间戳

    在第 825 行的 app/Mage.php 中引用此代码

     $format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
     $formatter = new Zend_Log_Formatter_Simple($format);
    

    干杯

    【讨论】:

    • 很棒的解释。谢谢
    猜你喜欢
    • 2017-12-21
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2013-08-05
    相关资源
    最近更新 更多