[Kimchi-devel] [PATCH] [Wok 2/2] Log time in ISO format
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Jun 8 01:45:59 UTC 2016
The same I commented on patch 1.
Update the API.md as this patch also changed the API and add/change the
test cases to confirm it keeps working.
On 06/03/2016 06:40 PM, Lucio Correia wrote:
> Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
> ---
> src/wok/reqlogger.py | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/src/wok/reqlogger.py b/src/wok/reqlogger.py
> index 2ec62b8..6f32c44 100644
> --- a/src/wok/reqlogger.py
> +++ b/src/wok/reqlogger.py
> @@ -23,9 +23,9 @@ import json
> import logging
> import logging.handlers
> import os.path
> +import time
>
> from cherrypy.process.plugins import BackgroundTask
> -from datetime import datetime
> from tempfile import NamedTemporaryFile
>
> from wok.config import config, get_log_download_path
> @@ -37,11 +37,12 @@ from wok.utils import ascii_dict, remove_old_files
> FILTER_FIELDS = ['app', 'date', 'download', 'ip', 'req', 'user', 'time']
> LOG_DOWNLOAD_URI = "/data/logs/%s"
> LOG_DOWNLOAD_TIMEOUT = 6
> -LOG_FORMAT = "[%(date)s %(time)s] %(req)-6s %(app)-11s %(ip)-15s %(user)s: " \
> - "%(message)s\n"
> +LOG_FORMAT = "[%(date)s %(time)s %(zone)s] %(req)-6s %(app)-11s %(ip)-15s " \
> + "%(user)s: %(message)s\n"
> RECORD_TEMPLATE_DICT = {
> 'date': '',
> 'time': '',
> + 'zone': '',
> 'req': '',
> 'app': '',
> 'ip': '',
> @@ -49,6 +50,9 @@ RECORD_TEMPLATE_DICT = {
> 'message': '',
> }
> SECONDS_PER_HOUR = 360
> +TS_DATE_FORMAT = "%Y-%m-%d"
> +TS_TIME_FORMAT = "%H:%M:%S"
> +TS_ZONE_FORMAT = "%Z"
>
> # Log handler setup
> REQUEST_LOG_FILE = "wok-req.log"
> @@ -180,10 +184,11 @@ class RequestRecord(object):
> self.message = message
> self.kwargs = kwargs
>
> - # register timestamp
> - timestamp = datetime.today()
> - self.kwargs['date'] = timestamp.strftime('%Y-%m-%d')
> - self.kwargs['time'] = timestamp.strftime('%H:%M:%S')
> + # register timestamp in local time
> + timestamp = time.localtime()
> + self.kwargs['date'] = time.strftime(TS_DATE_FORMAT, timestamp)
> + self.kwargs['time'] = time.strftime(TS_TIME_FORMAT, timestamp)
> + self.kwargs['zone'] = time.strftime(TS_ZONE_FORMAT, timestamp)
>
> def __str__(self):
> info = json.JSONEncoder().encode(self.kwargs)
More information about the Kimchi-devel
mailing list