File logging is working but not Console logging!

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

File logging is working but not Console logging!

James Pittman
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

Ivan Habunek
On 22 January 2013 22:26, James Pittman <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

James Pittman
On Tue, Jan 22, 2013 at 4:32 PM, Ivan Habunek <[hidden email]> wrote:
On 22 January 2013 22:26, James Pittman <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

Ivan Habunek
On 22 January 2013 22:36, James Pittman <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

James Pittman
On Tue, Jan 22, 2013 at 4:44 PM, Ivan Habunek <[hidden email]> wrote:
On 22 January 2013 22:36, James Pittman <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

Ivan Habunek
On 23 January 2013 03:52, James Pittman <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

James Pittman
On Wed, Jan 23, 2013 at 2:25 AM, Ivan Habunek <[hidden email]> wrote:
On 23 January 2013 03:52, James Pittman <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File logging is working but not Console logging!

Ivan Habunek
On 23 January 2013 13:43, James Pittman <[hidden email]> 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
Loading...