Joomla >1.7 从浏览器隐藏日志消息 [英] Joomla >1.7 hide log messages from browser

查看:7
本文介绍了Joomla >1.7 从浏览器隐藏日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Joomla 开发一个扩展!目前我正在尝试使其与 3.0 兼容 - 与 3.0 一样,日志记录略有变化(*).基于 这个相关问题的答案,我当前的代码如下所示:

I'm developing an extension for Joomla!; at the moment I'm trying to make it 3.0 compatible - as with 3.0 the logging changed a little (*). Building on the answer from this related question, my current code looks like this:

JLog::addLogger(array(
    'text_file' => 'plg_system_myplg.log.php'
)); 
JLog::add('blah blah log msg');

问题是日志也会转到向用户显示的消息中 - 我想防止这种情况,我希望日志味精只转到日志文件.我认为这与 JLog::add 作为第三个(可选)参数的类别"有关,但我不知道要传递什么?

The problem is that the log also goes to the messages which are shown to the user - this I want to prevent, I want the log msg only to go to the log file. I think it has to do with the "category" that JLog::add takes as a 3rd (optional) parameter, but I have no idea what to pass there?

谁能告诉我如何隐藏消息/或告诉我我是否对类别正确以及我应该使用什么值?

Can anybody tell me how to hide the messages / or tell me if I'm on the right way with the categories and what value I should use?

谢谢!

(*) 就我目前收集到的而言,它实际上已经在 1.7 中发生了变化,但是在 JLog::getInstance(...) 返回时调用 addEntry 的旧方法似乎有已从 2.5 删除到 3.0.

(*) It actually changed already with 1.7 as far as I gathered so far, but the old method of calling addEntry on the return of JLog::getInstance(...) seems to have been removed from 2.5 to 3.0.

认为我现在找到了方法;使用:

Think I found a way now; using:

JLog::addLogger(array(
    'text_file' => 'plg_system_myplg.log.php',
    JLog::ALL,
    'myplg'
)); 

JLog::add('blah blah log msg', JLog::INFO, 'myplg');

我所有的日志条目只进入我的日志文件(而不是显示给用户的消息).但是,我也收到了一些弃用警告 - 一个关于我的代码,还有一些不相关的:

all my log entries go only into my log file (and not to the messages shown to the user). However, I also get a few deprecation warnings - one about my code, but also some unrelated ones:

WARNING deprecated  JAccess::getActions is deprecated. Use JAccess::getActionsFromFile or JAcces::getActionsFromData instead.
WARNING deprecated  JSubMenuHelper::getEntries() is deprecated. Use JHtmlSidebar::getEntries() instead.
WARNING deprecated  JSubMenuHelper::getFilters() is deprecated. Use JHtmlSidebar::getFilters() instead.
WARNING deprecated  JSubMenuHelper::getAction() is deprecated. Use JHtmlSidebar::getAction() instead.

不知道如何处理这些 - 为什么它们出现在我的日志文件中,它们不应该转到默认的 error.log 文件而不是我的文件吗?

Not sure what to make of those - why do they appear in my log file, shouldn't they go to the default error.log file instead of my file ?

推荐答案

这是我正在使用的,适用于 Joomla 1.5 - 3.2:

This is what I am using, works for Joomla 1.5 - 3.2:

if(version_compare(JVERSION,'1.7.0','ge')) {
   jimport('joomla.log.log'); // Include the log library (J1.7+)   
   $priorities = JLog::ALL ^ JLog::WARNING; // exclude warning (because of deprecated)
   // In J3.0 we need to ensure that log messages only go to our file, thus use the categories (already supported in J2.5)      
   if(version_compare(JVERSION,'2.5.0','ge')) {
      $logCategory = 'com_mycomponent';
      JLog::addLogger(array('text_file' => $logFileName), $priorities, $logCategory);
      JLog::add($msg, JLog::INFO, $logCategory);
   }else{
      JLog::addLogger(array('text_file' => $logFileName), $priorities);
      JLog::add($msg, JLog::INFO);
   }
} else {
   // Joomla! 1.6 and 1.5
   jimport('joomla.error.log'); // Include the log library
   $log = &JLog::getInstance($logFileName);
   $log->addEntry(array('comment' => $msg, 'level' => 'INFO'));   
}

这显示了获取已弃用消息的技巧.

This shows the trick for gettring of the deprecated messages.

是的,您必须为您的消息添加一个类别,以确保它们不会显示为系统消息.

And yes, you have to include a category for your messages to ensure they are not showing up as system messages.

这篇关于Joomla >1.7 从浏览器隐藏日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆