Cannot get any kind of logging to work on Windows

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Cannot get any kind of logging to work on Windows

Postby ajax » 19. June 2019 19:42

This pertains to xampp 7.2.17 running on Windows 10. I'm afraid I can't use xampp 7.3 for this project because the Wordpress plugins/themes I'm using fail to function correctly.

The problem is that NO matter what I specify in php.ini when I run phpinfo it says that

error_log = \xampp\php\logs\php_error_log

and nothing gets logged. This is true even when I comment all instances of the setting named error_log as well as when I set "error_log = system" which, as I understand it, should specify usage of the Windows System logs. Curiously, in the distributed version of php.ini the error_log setting occurs in 2 different places. The second instance is in a block of code that appears to be referred to as pertaining to Module Settings

Interestingly until I created a file named \xampp\php\logs\php_error_log, hoping that might help, there was NOT even a directory named logs within the directory named php.

There is a reasonable possibility that I'm a sufficient enough novice NOT to know about inter-dependencies that might have this affect. However, attempts to find an explanation in the both the online documentation for PHP as well as some books of mine have been futile.

If someone could either explain what's wrong or refer me to documentation that might be helpful I'd be most grateful. My primary interest, at the moment, is to be able to use the error_log function to record events useful for trouble shooting.
ajax
 
Posts: 21
Joined: 14. December 2010 17:57
Operating System: Windows 2000 Professional

Re: Cannot get any kind of logging to work on Windows

Postby Nobbie » 19. June 2019 19:55

As i dont like the relative pathes, i would apply a drive letter anyway, for example c:/xampp/... etc.

Additionally, i dont like the backslash in WIndows Pathes (as Backslash also is a metacharacter in PHP strings), therefore i also recommend using slash instead (Windows Kernel can handle slash as well as backslash). Maybe it helps. Simply give it a try.
Nobbie
 
Posts: 11148
Joined: 09. March 2008 13:04

Re: Cannot get any kind of logging to work on Windows

Postby JJ_Tagy » 20. June 2019 01:49

I agree with Nobbie. I use
Code: Select all
error_log =  "C:\xampp\php\logs\php_error_log"


Also, be aware that if PHP isn't parsing anything, it won't put any errors in the log. I mention that in case you are having Apache issues.
JJ_Tagy
 
Posts: 762
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64

Re: Cannot get any kind of logging to work on Windows

Postby ajax » 20. June 2019 21:03

It looks as though my mistake accounts for the issue associated with repeatedly running phpinfo.php and seeing nothing change. I think I was editing php.ini and then rerunning phpinfo.php without restarting Apache. Apparently php.ini is not reprocessed except when initializing Apache. It seems like maybe there should be a way to do that but NOT to my knowledge. Possibly someone can explain if there is a way to update PHP settings without restarting Apache.

With respect to the syntax used for file names in php.ini I was following the example used in the XAMPP distribution where it looks like absolute paths are those that start with \xampp (or /xampp if you prefer). The point being it appears as though xampp will use the drive (letter) of the drive where it knows the current xampp is running from. I've now done it with both "/" and "\" as well as both with and without drive letter and while phpinfo.php now correctly displays the value used in php.ini there is still nothing being written to the log.

The settings from php.ini are as follows:

; http://php.net/log-errors
log_errors = On
...
;error_log = php_errors.log
; ***DG*** revised 6/19/2019
error_log = "W:/xampp/htdocs/logs/php_errors.log"
; Log errors to syslog (Event Log on Windows).
;error_log = syslog


The code block from my Wordpress theme that I'm wanting to alter follows:

/***DG curious to see what _x returns
if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
// */
//***DG curious to see what _x returns
$out = _x( 'on', 'Lato font: on or off', 'twentyfourteen' );
error_log("Translate Lato = ".$out, 0);
if ( 'off' !== $out ) {
// */


This snipet shows both the original code, presently commented, along with my replacement coded such that reversing what gets used is a matter of simply adding/removing a couple of slashes. Both versions produce the same, what looks to be error free, result when invoked but nothing appears in the error log file.

What have I missed?
ajax
 
Posts: 21
Joined: 14. December 2010 17:57
Operating System: Windows 2000 Professional

Re: Cannot get any kind of logging to work on Windows

Postby Nobbie » 20. June 2019 23:20

What is W:?

A drive letter for network drives has a restricted scope, it only exists for the currently logged in user. If you run Apache and PHP as a service, it is NOT executed by your User, but from SYSTEM User instead. In that case W: is an invalid drive letter.

Put the logfile onto C: instead.
Nobbie
 
Posts: 11148
Joined: 09. March 2008 13:04

Re: Cannot get any kind of logging to work on Windows

Postby ajax » 21. June 2019 18:30

W: is an internal hard disk (NTFS partition). It is the drive on which xampp resides along with all other files that I consider to pertain to my work product. My C: drive is a relatively small SSD that contains no files that need to be preserved (i.e., user work product). I use multi-boot (i.e., several Windows partitions on C: drive) for backing up Windows. Most of my application software is portable and is stored/run on/from a solid state thumb drive. I tried running xampp this way but it didn't work very good. Appears that running web servers & databases involves too much writing data to disk for what a thumb drive can handle.

My XAMPP is the portable rather than installed version. With the exception of logging everything is working fine. I'd point out that no other file specifications in php.ini include a drive letter. Neither did this one until it was suggested herein. I'm having a hard time contemplating an explanation for why logging would be something peculiar enough that it is the only thing that doesn't work in my configuration.
ajax
 
Posts: 21
Joined: 14. December 2010 17:57
Operating System: Windows 2000 Professional

Re: Cannot get any kind of logging to work on Windows

Postby ajax » 21. June 2019 19:04

Just discovered something that should be helpful. Decided to search within the xampp directory to see if I could find something that looked like a log file located anywhere. Low and behold such a file was found. It is named "debug.log". It resides in the "wp_content" directory of the Wordpress site I'm testing. It contains the records I've been writing with the error_log function.

This implies to me that Wordpress could be overriding the settings specified in php.ini and using what it prefers. I'm pretty sure this isn't based on anything I intended to do when setting up Wordpress but it could easily be something I don't understand about how Wordpress, which is (itself) pretty complicated, normally functions.

Possibly you xampp experts would know if such an override is something that php allows and if so maybe provide reference to some documentation which might explain how it is done.

To the extent that I now seem to know about it this is fine for what I'm doing now. I'd just like to better understand how php intends this to work.
ajax
 
Posts: 21
Joined: 14. December 2010 17:57
Operating System: Windows 2000 Professional

Re: Cannot get any kind of logging to work on Windows

Postby Nobbie » 22. June 2019 11:54

ajax wrote:Possibly you xampp experts would know if such an override is something that php allows and if so maybe provide reference to some documentation which might explain how it is done.


Come on, thats really poor! You're a thinking creature, aren't you? I'm gonna go over this with you now, but you're gonna be embarrassed.

What is the context? Clearly php.ini - we wanna know about PHP configuration. Gladly, we have internet and we have Google. Simple enough, we enter "php.ini" into Google. Full success - already the first hit is a direct hit: php.ini configuration file

The documentation about php.ini opens (evtly. choose your own language). On the right side is a small menu with a couple of topics, two of them are exactly what we are looking for:

Where a configuration setting may be set
How to change a configuration setting

Click on the first topic (do it!) and read it. You will learn, that php configuration settings can be set per USER, per SYSTEM, per Directory or anywhere (depends on the option). And there is already mentioned, how to change an option within a php script (what you are looking for):

"For example, some settings may be set within a PHP script using ini_set(), whereas others may require php.ini or httpd.conf."

Aha! There is a function ini_set() which allows to manipulate (some) options at runtime. Anyway, now we click on the second topic, in order to find out, how to change configuration options. Do it! Read it!

Ok, i will skip that (but you MUST read it!), as we already know, that we possibly may use ini_set() in a php script. What we still dont know: does this apply for our configuration? What are we looking for? We are looking for the setting of error_log, we need to know, where can i change this setting. Only in php.ini? Or (hopefully) also at runtime in scripts?

If you read the second topic, there is a link to List of php.ini directives. Very nice! Again, we click on that and then we proceed to... error_log (whereelse?)! Where can error_log be changed? Anywhere! Thats what PHP_INI_ALL means. Ok, now we know for sure: a php script (like wordpress) can change the setting of error_log at runtime. And how? With a call to the function ini_set(), but which parameters?

Nothing easier than that, we proceed to the documentation of ini_set() (there are already a couple of links to it in the documentation we already read). Or simply enter "ini_set" into the search box in the upper right corner and proceed to the function ini_set(). Very intuitive and very easy, still! ini_set() requires two arguments, the name of the option, the value of the option. Not a big surprise, isnt it?

Youre done! Congratulations! I have good news for you: you are an Xampp expert now! Because you think, one must be an Xampp expert for finding/knowing documentation about manipulation php.ini settings at runtime. Only experts can find this hidden treasure, the documentation about php.ini. You found it - so you are an expert! Welcome on board!
Nobbie
 
Posts: 11148
Joined: 09. March 2008 13:04

Re: Cannot get any kind of logging to work on Windows

Postby ajax » 22. June 2019 18:12

Very nice lesson! That is what I was asking for and would never have expected such a thorough response. Many thanks for that.

When it comes to embarrassment I'm senior enough to have given up on the idea of trying to hide my ignorance. Maybe I should remind that what makes XAMPP so great is how easy it is to get it working and use it without having had to learn everything there is to know about all of the parts, which by the way are constantly changing and becoming even more complicated.

Yes, my own continued googling may have eventually lead to this same finding but the marvelous thing about community support is when you are able to more quickly benefit from the experience of others who've already done it and who know what you now want to learn.

Very Nice, Thanks Again!
ajax
 
Posts: 21
Joined: 14. December 2010 17:57
Operating System: Windows 2000 Professional

Re: Cannot get any kind of logging to work on Windows

Postby Nobbie » 22. June 2019 20:37

ajax wrote:When it comes to embarrassment I'm senior enough to have given up on the idea of trying to hide my ignorance.


What does "senior" mean in numbers? I don't really think that age prevents you from becoming active yourself. In the end I'm not the youngest anymore, but that doesn't stop me in any way from continuing to interest myself and reading documentaries.

ajax wrote:Yes, my own continued googling may have eventually lead to this same finding but the marvelous thing about community support is when you are able to more quickly benefit from the experience of others who've already done it and who know what you now want to learn.


Why can some help so much, others not at all? What is your field of knowledge, where can I read your advice? What is your part of the community?
Nobbie
 
Posts: 11148
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 104 guests