You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-user@logging.apache.org by James Pittman <jp...@gmail.com> on 2013/01/22 22:26:01 UTC

File logging is working but not Console logging!

Using the examples in the instructions, I created a config file and PHP
file.  I am getting the expected logging in the myLog.log, but nothing in
my STDOUT.  If I do NOT include the config.xml file, I DO get logging in
STDOUT.  Any ideas?


XML file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="default" class="LoggerAppenderFile">
        <layout class="LoggerLayoutSimple" />
        <param name="file" value="myLog.log" />
        <param name="append" value="true" />
    </appender>
    <appender name="FooAppender" class="LoggerAppenderConsole" />
    <root>
        <appender_ref ref="default" />
    </root>
    <looger name="Foo">
        <appender_ref ref="FooAppender" />
        <level value="debug" />
    </looger>
</configuration>


My PHP file:
<?php
ini_set("display_errors", 1);
// Include and configure log4php
include('log4php/Logger.php');
Logger::configure('config.xml');

$logger = Logger::getLogger("main");
$logger->info("Logging from main.");

/**
 * This is a classic usage pattern: one logger object per class.
 */
class Foo {

    /** Holds the Logger. */
    private $log;

    /** Logger is instantiated in the constructor. */
    public function __construct() {
// The __CLASS__ constant holds the class name, in our case "Foo".
// Therefore this creates a logger named "Foo" (which we configured in the
config file)
        $this->log = Logger::getLogger(__CLASS__);
    }

    /** Logger can be used from any member method. */
    public function go() {
        $this->log->info("Logging from Foo.");
    }

}

$foo = new Foo();
$foo->go();
?>




-- 
____________________________________________________________________________________
Taste and see the fullness of His peace, and hold on to what's being held
out.
~ from "The Healing Hand of God" by Matthew West

Re: File logging is working but not Console logging!

Posted by Ivan Habunek <iv...@gmail.com>.
On 23 January 2013 13:43, James Pittman <jp...@gmail.com> wrote:
> Interesting.  If you do just
> print "Hello World";
>
> It will print to console and browser - I just assumed that was stdout.

Print and echo actually write to php://output stream, and not
php://stdout. Frankly, I'm not sure exactly what happens under the
hood, just what it says in the manual. Maybe someone else on the list
can explain it better.

Regards,
Ivan

Re: File logging is working but not Console logging!

Posted by James Pittman <jp...@gmail.com>.
On Wed, Jan 23, 2013 at 2:25 AM, Ivan Habunek <iv...@gmail.com>wrote:

> On 23 January 2013 03:52, James Pittman <jp...@gmail.com> wrote:
> > Yes that was it.  I was trying to output it to a browser.  I shouldn't
> have
> > said "console stdout" - I just assumed that if it would output to a
> console,
> > it would output to a browser... but it must check to see whether you're
> in a
> > browser or CLI.
>
> Well not exactly, the appender makes no checks. It's just that writing
> directly to stdout will not output anything to the browser when using
> apache.
>
> Check out this link:
> http://stackoverflow.com/questions/11318768/php-stdout-on-apache
>

Interesting.  If you do just
print "Hello World";

It will print to console and browser - I just assumed that was stdout.

Jamie

Re: File logging is working but not Console logging!

Posted by Ivan Habunek <iv...@gmail.com>.
On 23 January 2013 03:52, James Pittman <jp...@gmail.com> wrote:
> Yes that was it.  I was trying to output it to a browser.  I shouldn't have
> said "console stdout" - I just assumed that if it would output to a console,
> it would output to a browser... but it must check to see whether you're in a
> browser or CLI.

Well not exactly, the appender makes no checks. It's just that writing
directly to stdout will not output anything to the browser when using
apache.

Check out this link:
http://stackoverflow.com/questions/11318768/php-stdout-on-apache

Regards,
Ivan

Re: File logging is working but not Console logging!

Posted by James Pittman <jp...@gmail.com>.
On Tue, Jan 22, 2013 at 4:44 PM, Ivan Habunek <iv...@gmail.com>wrote:

> On 22 January 2013 22:36, James Pittman <jp...@gmail.com> wrote:
> > OK I fixed that, but I'm still not getting any console stdout.
>
> That's strange. Works for me...
> http://i.imgur.com/22BB8Ly.png
>
> Note that the console appender output will not be seen in browser,
> only via CLI. Just noticed this is not in the docs. :) In that case
> you have to use LoggerAppenderEcho.
>
> Does this help? If not, which version of php and log4php are you using?
>

Yes that was it.  I was trying to output it to a browser.  I shouldn't have
said "console stdout" - I just assumed that if it would output to a
console, it would output to a browser... but it must check to see whether
you're in a browser or CLI.

Thanks!

Jamie

Re: File logging is working but not Console logging!

Posted by Ivan Habunek <iv...@gmail.com>.
On 22 January 2013 22:36, James Pittman <jp...@gmail.com> wrote:
> OK I fixed that, but I'm still not getting any console stdout.

That's strange. Works for me...
http://i.imgur.com/22BB8Ly.png

Note that the console appender output will not be seen in browser,
only via CLI. Just noticed this is not in the docs. :) In that case
you have to use LoggerAppenderEcho.

Does this help? If not, which version of php and log4php are you using?

Regards,
Ivan

Re: File logging is working but not Console logging!

Posted by James Pittman <jp...@gmail.com>.
On Tue, Jan 22, 2013 at 4:32 PM, Ivan Habunek <iv...@gmail.com>wrote:

> On 22 January 2013 22:26, James Pittman <jp...@gmail.com> wrote:
> > Using the examples in the instructions, I created a config file and PHP
> > file.  I am getting the expected logging in the myLog.log, but nothing
> in my
> > STDOUT.  If I do NOT include the config.xml file, I DO get logging in
> > STDOUT.  Any ideas?
>
> Yes!
>
> s/looger/logger/
>
> You misspelled <logger> in your config file. :)
>
> Regards!
> Ivan
>

LOL!

OK I fixed that, but I'm still not getting any console stdout.

Jamie

Re: File logging is working but not Console logging!

Posted by Ivan Habunek <iv...@gmail.com>.
On 22 January 2013 22:26, James Pittman <jp...@gmail.com> wrote:
> Using the examples in the instructions, I created a config file and PHP
> file.  I am getting the expected logging in the myLog.log, but nothing in my
> STDOUT.  If I do NOT include the config.xml file, I DO get logging in
> STDOUT.  Any ideas?

Yes!

s/looger/logger/

You misspelled <logger> in your config file. :)

Regards!
Ivan