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

is there any algorithm to generate sequential numbers based on the last number in the database?
Second updating page files disappear
PHP execition flow with interpretation and dynamic linking
I'm making too many API requests and I need help optimising it
data passing through ajax request
ZF2 Form getData with multiple fieldsets only returns data for one fieldset
Converting plain text csv rows into binary output
Why won't this simple redirect script work?
Save data to two different tables in CakePHP 3
CakePhp remember me option
PHP JSON generation problems
Append an INSERT into SQL by a loop
PHP MWS Samples set up, returning a blank screen.
Laravel 5.2 Migration: Cannot add foreign key of char data type
datatables ajax post causing null value to change to empty string ie. “”
how to proxy a request to a page just for validation in apache?

Categories

HOME
user-interface
softlayer
concurrency
visual-studio-2010
odata
semantic-web
autocomplete
drag-and-drop
stored-procedures
cdi
kurento
msmq
elastic-load-balancer
scrape
fasm
parsley.js
orc
jquery-file-upload
webstore
temperature
asciimath
office-ui-fabric
gitkraken
hdl
kaggle
gollum-wiki
uislider
sybase-ase
jpa-2.1
tortoisemerge
hevc
materialize
credit-card
tightvnc
snap-framework
nsmutablearray
amazon-kms
transform
runtimeexception
grails-spring-security
hdiv
web-inspector
code-push
linq-to-excel
axis
realstudio
section508
cloudwatch
libreoffice-writer
brightscript
karabiner
portability
rcharts
prefetch
scheduledexecutorservice
dpkg
codecharge
python-cffi
in-app-billing
self
mixins
dbmigrate
console.log
uno
configurable-product
mobile-country-code
full-text-indexing
category-theory
webautomation
neo4jphp
rails-api
bittorrent-sync
unrealscript
virtual-channel
void-pointers
reentrancy
system-requirements
daap
websphere-6.1
kolite
expression-web
botnet
css-friendly
qcar-sdk
pyjamas
git-log
active-record-query
cassini
pinax
tacit-programming
regioninfo
account-management

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