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

查看:114
本文介绍了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');

问题是日志也转到显示给用户的消息-这是我要防止的,我希望日志msg仅转到日志文件.我认为这与JLog::add作为第3个(可选)参数的类别"有关,但是我不知道该在那里传递什么?

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天全站免登陆