log4php 将无法正常工作

发布于 2024-09-28 12:25:37 字数 2012 浏览 5 评论 0原文

因此,我最近发现 log4* 软件包可用于 PHP,看到这一点后,我急切地从 log4php 网站下载了最新的软件包,并按照安装说明进行操作。说明是下载tar包,解压后将以下目录放在自己选择的地方:log4php/src/main/php

因此我复制了log4php/src/main/php<的内容/code> 进入 lib/log4php 下的 lib 目录。

在我的脚本中,根据需要,我需要“Logger.php”类并指示一个属性文件来管理我的附加程序。属性文件 log4php.properties 位于我的文件系统上的“/home1/ioforgec/www/devlab/pnotes/config/log4php.properties”。

这是日志文件内容:

#
# Example Logger
#
log4php.appender.EA1 = LoggerAppenderConsole
log4php.appender.EA1.target = STDOUT
log4php.appender.EA1.layout = LoggerLayoutPattern
log4php.appender.EA1.ConversionPattern = "%m"
log4php.appender.EA1.threshold = FATAL
log4php.exampleLogger = FATAL, EA1

所以这是我的脚本的副本,它实现了(或多或少“包装”了 log4php 功能):

<?php

require_once('/home1/ioforgec/www/devlab/pnotes/lib/log4php/Logger.php');

class LogUtil
{
    public $logger;

    public $properties_file = "/home1/ioforgec/www/devlab/pnotes/config/log4php.properties";

    public static function logExample($msg)
    {
        Logger::configure($properties_file);
        $logger = Logger::getLogger("example");
        $logger->debug("Shouldnt see this print because of config max level FATAL");
        $logger->fatal($msg);
    }
}
?>

为了测试它是否正常工作,以下脚本调用上面显示的 LogUtil.php

#!/usr/bin/php
<?php
require_once("lib/utils/LogUtil.php");
LogUtil::logExample("example message");
?>

: ,尽管配置示例记录器将消息格式化为纯消息,尽管将记录器的级别设置为最大值 FATAL,不仅在记录器声明中而且在阈值命令中,在我看来,控制台的打印看起来像默认根记录器:

Mon Oct 18 20:30:05 2010,705 [827] DEBUG example - Shouldnt see this print because of config max level FATAL
Mon Oct 18 20:30:05 2010,711 [827] FATAL example - example message

我看到打印语句没有指定的纯格式,并且我看到两个打印语句,即调试打印(由于记录器配置上的 FATAL 设置,该语句永远不应该打印 - FATAL 比 DEBUG 高得多) )

我到底做错了什么?我已经尝试了我能想到的所有设置组合。有人有什么建议吗?

编辑 - 更新 - 这仍然是一个问题。没有进展。

编辑2-真的吗?这个论坛上没有人尝试使用这个非常流行的日志记录包及其作为 PHP 模块的化身吗?

我已经尝试了所有可以想到的途径来尝试回答我的问题,包括 log4php 用户的邮件列表。

So I recently discovered that the log4* package was available for PHP and upon seeing this eagerly downloaded the latest from the log4php website and followed the installation instructions. The instructions indicate that one is to download the tar package, untar, and place the following directory in a place of one's choosing: log4php/src/main/php

Therefore I copied the contents of log4php/src/main/php into my lib dir under lib/log4php.

In my script, as required, I required the 'Logger.php' class and indicated a properties file to manage my appenders. The properties file, log4php.properties, is located on my filesystem at "/home1/ioforgec/www/devlab/pnotes/config/log4php.properties".

Here is the logfile content:

#
# Example Logger
#
log4php.appender.EA1 = LoggerAppenderConsole
log4php.appender.EA1.target = STDOUT
log4php.appender.EA1.layout = LoggerLayoutPattern
log4php.appender.EA1.ConversionPattern = "%m"
log4php.appender.EA1.threshold = FATAL
log4php.exampleLogger = FATAL, EA1

So here is a copy of my script that implements (more or less 'wraps' the log4php functionality):

<?php

require_once('/home1/ioforgec/www/devlab/pnotes/lib/log4php/Logger.php');

class LogUtil
{
    public $logger;

    public $properties_file = "/home1/ioforgec/www/devlab/pnotes/config/log4php.properties";

    public static function logExample($msg)
    {
        Logger::configure($properties_file);
        $logger = Logger::getLogger("example");
        $logger->debug("Shouldnt see this print because of config max level FATAL");
        $logger->fatal($msg);
    }
}
?>

In order to test that this is working properly, the following script calls the LogUtil.php shown above:

#!/usr/bin/php
<?php
require_once("lib/utils/LogUtil.php");
LogUtil::logExample("example message");
?>

So, despite configuring the example logger to format the messages as the plain message, despite setting the level of the logger to a max of FATAL, not only in the logger declaration but also in the threshold command, the print to the console looks to me like the default root logger:

Mon Oct 18 20:30:05 2010,705 [827] DEBUG example - Shouldnt see this print because of config max level FATAL
Mon Oct 18 20:30:05 2010,711 [827] FATAL example - example message

I see the print statement without the plain formatting as specified, and I see two print statements, the debug print (which should never have printed due to the setting of FATAL on the logger config - FATAL is MUCH higher than DEBUG)

What on earth am I doing wrong? Ive tried every combination of setup I can possibly think of. Does anyone have any suggestions?

Edit - Update - This is still an issue. No progress.

Edit2 - Really? Has no one on this forum tried to use this very popular logging package and its incarnation as a PHP module?

I have tried every conceivable avenue to try and get my question answered, including the log4php user's mailing list.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2024-10-05 12:25:37

经过许多个小时的操作配置文件后,我发现了一个小但极其重要的事实。为了指定“记录器”,您必须在“记录器”层次结构下命名它,并在“附加程序”层次结构下命名它的附加程序,等等。例如:

# for the 'console' logger named 'example' we first define the appender:
log4php.appender.consoleAppender = LoggerAppenderConsole
log4php.appender.consoleAppender.target = STDOUT
log4php.appender.consoleAppender.layout = LoggerLayoutSimple

# we then assign the appender and the minimum log level to the logger:
log4php.logger.example = WARN, consoleAppender

我的错误是看到根记录器层次结构名称“log4php.rootLogger”和假设为了分配记录器,只需为“log4php.lognameLogger”命名一个值。遗憾的是,这不是借口,因为文档中隐藏了一个示例。我想在 9 个小时以上找到它总比根本没有好:)

感谢那些提醒我还有更多调试工作要做的人,我很感谢提醒我继续尝试

After many many more hours of manipulating the configuration file I have discovered a small, yet critically important factoid. In order to specify a 'logger' you must name it under the 'logger' hierarchy and its appenders under the 'appender' hierarchy, etc etc. For example:

# for the 'console' logger named 'example' we first define the appender:
log4php.appender.consoleAppender = LoggerAppenderConsole
log4php.appender.consoleAppender.target = STDOUT
log4php.appender.consoleAppender.layout = LoggerLayoutSimple

# we then assign the appender and the minimum log level to the logger:
log4php.logger.example = WARN, consoleAppender

My mistake was in seeing the root logger hierarchy name 'log4php.rootLogger' and assuming that in order to assign a logger one need only name a value for 'log4php.lognameLogger'. Sadly this is no excuse as there was an example, buried, in the documentation. I suppose finding it at 9+ hours is better than not at all :)

Thanks to those who reminded me that there was more debugging work to be done, I appreciated the reminder to keep trying

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文