php


log4php and timezone


Does anyone know if it is possible to set timezone in the log4php library configuration?
I did not see any information regarding this in the official docs, but log4j has this implemented.
Right now, I am relying on php's *date_default_timezone_set* function to do the trick, but I wanted to leave log4php to handle this on its own... I wonder if there is a to-do list for this or we are supposed to rely on the built-in function by ourselves.
Here is the code I have:
date_default_timezone_set("America/New_York");
require_once (dirname(__FILE__) . '/lib/log4php/Logger.php');
Logger::configure(
array(
'appenders' => array(
'default' => array(
'class' => 'LoggerAppenderRollingFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%d{Y-m-d H:i:s.u} [%t] %-5p - %m%n'
)
),
'params' => array(
'file' => '/var/log/myapp/myapp.' . date('Y-m-d') . '.log',
'maxFileSize' => '1MB',
'maxBackupIndex' => 10,
),
),
),
'rootLogger' => array(
'appenders' => array('default'),
),
)
);
$logger = Logger::getLogger('myapp');
for( $i=0; $i<5000; $i++ ) {
$logger->info("This is a test [${i}].");
}
In case this code serves someone else with similar issue.
Be safe,
A defined default timezone belongs to a fully working php application.
Apart from that, you are not very clear in stating what you expect log4php to do. The project has everything from mailing list to issue tracker - you are welcome to send your wishes.
I had a similar problem. You can log the date and time for UTC/GMT in the log4php by changing one line of code in the module.
Here is how I did. Go to the module and find the file LoggerPatternConverterDate.php.
cd log4php/pattern/
vim LoggerPatternConverterDate.php
Find the private function date($format, $utimestamp) (Line 84 for me) and change the line of code that returns.
This:
return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
Becomes:
return gmdate(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
Also, find the file: log4php/appenders/LoggerAppenderDailyFile.php and change the following line:
This:
return date($this->datePattern, $timestamp);
Becomes:
return gmdate($this->datePattern, $timestamp);
NOTE: The only thing changed is the function used to format the date string. date() depends on timezone that you set using date_default_timezone_set whereas gmdate() formats the date and time in UTC/GMT irrespective of default timezone.

Related Links

php built in webserver not reacheable with ip:port via network cable
I cant get value of the radio button Except first radio button
Edit iframe content using PHP, and preg_replace()
PMPRO Wordpress plugin Membership Cancellation Errors (stripe)
Android HttpURLConnection Post Data, PHP App Server can't receive data
compare todays date with the date in the mysql table using codeigniter
Get all possible combinations without duplicates
how to upload to files to amazon EC2
Getting the top scores, but remove duplicate users (SQL)
Explode a string after 5 spaces and 2 new lines in a string in PHP
How to create a button that links to different URL using if-else statement
How to display category's items?
Distinguish tr in dynamic table form for serializing jQuery
phpMyAdmin doesn't show new databases
decode base64 and pass to zip file
Passing POST data from ionic framework to CodeIgniter Rest API

Categories

HOME
xpath
orientdb
firebase
bokeh
long-integer
couchdb
bots
key
transactions
hid
code-formatting
ews
filesize
biztalk
jersey-2.0
drag-and-drop
linker
azure-mobile-services
xamarin-zebble
tiff
feature-extraction
cuba-platform
google-cloud-logging
word2vec
coroutine
codefluent
parceler
adobe-illustrator
activeadmin
sharedpreferences
cell
restier
vuforia
opentext
unordered-multimap
oracleforms
social-networking
intune
tightvnc
instructions
windowsiot
gsp
devtools
apptentive
polyml
wdk
nanogallery
llvm-ir
rdp
cloudera-sentry
flipkart
yoast
daz3d
webalizer
password-hash
sonicmq
openstack-glance
exc-bad-access
nivo-slider
wikimapia
sesame
hmmlearn
clp
right-to-left
wicked-pdf
strpos
utf-16
certificate-authority
teensy
apache-commons-digester
srv-record
jnlp
darwin
clarion
kotlin-android-extensions
incron
mutators
mod-auth-openidc
nhibernate-criteria
dos2unix
wicket-1.5
jquery-mobile-flipswitch
box2dweb
redpitaya
.htpasswd
hotswap
accountmanager
jomsocial
usb-flash-drive
code39
sensormanager
iirf
hints
red-system
multiple-dispatch
spark-view-engine
gitx
clearinterval
litespeed
asio
snackjs
firefly-mv
nosetests
qcar-sdk
multiple-users
odac
raw-data

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App