phpapacheconsolelog4php

where does Apache console output go when Apache is run as a service?


(Windows 7 OS) - I am working through Apache's log4php. This page http://logging.apache.org/log4php/quickstart.html seems to be for PHP run in a console window, rather than PHP run by an Apache webserver. I am however interested in logging in the latter context.

Under "Advanced example" the code logs as expected to the log file. But where it also says "This produces the following output in the console: INFO - We have liftoff", I am trying to find where this output is actually going. It didn't log to the browser or to any of the inbuilt Apache log files.

I found the following question to do with PHP stdout/output: PHP stdout on Apache - and then I ran (using BASH for Windows) the following command after shutting down the installed Apache service (to run Apache instead in the "foreground"):
httpd -D FOREGROUND -k start
No joy... this did not result in logging that "liftoff" message to the browser either. Nor has it logged to any of the inbuilt Apache log files. Any ideas where/if I can find the console output?


Solution

  • The LoggerAppenderConsole does log to STDOUT, optionally to STDERR.

    In the usual Apache context you don't have a console, so it is wrong to log to one. The usual way is to log to any of the logging facilities that are present: Files, syslog, PHP echo, databases, PHP trigger_error etc.

    If you want to have a visible output in this example with minimum changes, change the LoggerAppenderConsole to LoggerAppenderEcho. This closely resembles the output you would experience on the console, but now inside the generated HTML.

    Or you simply run the script on the command line on Windows. It would only need the path to the PHP executable, like C:\Whatever\Path\php.exe script.php.