The issue
I'm using PHP's apache_note() to log variables from web requests to a CustomLog format. However, try as I might, Apache doesn't want to log UTF-8 characters the way I'd like.
In PHP, I have apache_note('some_value', '✔'); which corresponds to the VHost config which looks like this:
LogFormat "%{some_value}n" custom_format CustomLog ${APACHE_LOG_DIR}/access.log custom_format
However, Apache ends up logging the literal version like this:
\xe2\x9c\x94 What I've tried
- Checked the values of both
LANGandLC_ALLand they are both set toen_US.UTF-8 - Updated
/etc/apache2/envvarsto use/etc/default/localeby default - Using mod_charset_lite I have set
CharsetSourceEnc UTF8andCharsetDefault UTF8in the Apache config for the site (I know this is for content in/out) - Checked that /etc/apache2/conf.d/charset has set
AddDefaultCharset UTF-8 - Tried sending the logging output through a piped log to another program - its
\xe2\x9c\x94by the time it gets there, so it certainly seems like its something to do with the Apache process itself. - Read through the Apache logs docs
Ultimately, I want that access log to show something like:
✔
but I'm pulling my hair out trying to get there.
Other information
- Apache version 2.4.10
- Debian 8.4
Update
Per Esa's suggestion, I modified the LogFormat directive:
LogFormat "%{some_value}n ✔" custom_format
And I get the following:
\xe2\x9c\x94 ✔
Which is interesting, because it suggests Apache's willingness to log UTF-8. However, I'm still not convinced that the issue has anything to do with PHP passing non UTF-8 values.
apache_note('some_value', '✔'); $value = apache_note('some_value'); print_r($value); in PHP still prints out
✔
I will try re-compiling Apache next to see fi it helps, but I do need this in production which may be dicey.
LogFormatdirective? This way you can narrow the problem down to either PHPapache_note()or Apache logging related. Apache uses the current locale and everything in your configuration looks consistent. Maybe the escaping happens withinapache_note()function or before it gets to variable%{some_value}.LogFormatdirective toLogFormat "%{some_value}n ✔" custom_formatand what do you know, it correctly logs a ✔. I'll update the information in the main question.