WebFaction
Community site: login faq

Hi.

I'm from Spain, where the current time is UTC + 01:00 (seven hours more than the server hour), but the time logged in the nginx and rails logs are the server time. Because of that, it's a bit annoying analyze the logs.

Is there any way to configure the logs to record my local time instead of the server time?

Thanks!

asked 30 Dec '10, 10:24

jorgeoa
1112
accept rate: 0%


You should be able to set the time zone by adding env TZ=TIMEZONE; to your nginx.conf file. Replace TIMEZONE with your correct time zone. Nginx has some documentation on it here:

http://wiki.nginx.org/CoreModule#env

permanent link

answered 30 Dec '10, 10:47

aaronh ♦♦
1.3k3
accept rate: 34%

I've already tried it, but it didn't work.

I tried these commands in nginx.conf file:

env TZ=UTC;

env TZ=Europe/London;

but the recorded time is the server time.

I've just tried another solution: set the timezone to Europe/Madrid in the ssh sessioon variable: export TZ="Europe/Madrid", and also in the nginx.conf file.

Now, the rails log records the right time (UTC+1), but nginx records the server time (CST/UTC-6)

(30 Dec '10, 12:18) jorgeoa

You might also need to add the TZ variable to your nginx start script (in ~/webapps/app_name/bin/start).. for example:

TZ=Europe/London GEM_HOME=/home/username/webapps/app_name/gems /home/username/webapps/app_name/nginx/sbin/nginx -p /home/username/webapps/app_name/nginx/
(30 Dec '10, 12:24) seanf

Same behaviour, rails records right time, but nginx server time :(

(30 Dec '10, 13:03) jorgeoa

The logs recorded by our front-end nginx server cannot be changed. Which logs are you looking at exactly?

(30 Dec '10, 14:03) johns

Hi johns. I was looking at the logs in logs/frontend/

Now, I see that the logs in logs/user/ records the right time when I set the TZ variable, but these logs don't record the client's ip address but the localhost ip (127.0.0.1) so they aren't very useful.

(31 Dec '10, 05:02) jorgeoa

Finally I found a solution.

As johns said, I can't modify the log format of logs in /home/user/logs/frontend, but I can change the logs en /home/user/logs/user.

To record the time in my time zone, I had to set the TZ variable in the nginx start script, as seanf told to me in a comment:

export TZ="Europe/Madrid"

Now the nginx and rails logs record my local time.

The problem in the user logs is that by default they record the localhost ip address instead of the client address, but you can solve this defining a new log_format like this:

log_format main '$proxy_add_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';

access_log /home/user/logs/user/access_app.log main;

The $proxy_add_x_forwarded_for variable contains the client's ip address and the localhost ip.

Thank you all for your comments.

permanent link

answered 31 Dec '10, 05:10

jorgeoa
1112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×186
×108
×15
×4

question asked: 30 Dec '10, 10:24

question was seen: 11,717 times

last updated: 31 Dec '10, 05:10

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM