Skip to content
Snippets Groups Projects
Commit a220e53b authored by Pavel Kácha's avatar Pavel Kácha
Browse files

Added format_timestamp helper function

parent 168609eb
No related branches found
No related tags found
No related merge requests found
...@@ -4,14 +4,13 @@ ...@@ -4,14 +4,13 @@
# Copyright (C) 2011-2015 Cesnet z.s.p.o # Copyright (C) 2011-2015 Cesnet z.s.p.o
# Use of this source is governed by a 3-clause BSD-style license, see LICENSE file. # Use of this source is governed by a 3-clause BSD-style license, see LICENSE file.
import json, httplib, ssl, socket, logging, logging.handlers import json, httplib, ssl, socket, logging, logging.handlers, time
from urlparse import urlparse from urlparse import urlparse
from urllib import urlencode from urllib import urlencode
from sys import stderr, exc_info from sys import stderr, exc_info
from pprint import pformat from pprint import pformat
from traceback import format_tb from traceback import format_tb
from os import path from os import path
from time import sleep
from operator import itemgetter from operator import itemgetter
...@@ -514,7 +513,7 @@ class Client(object): ...@@ -514,7 +513,7 @@ class Client(object):
while ev and attempt: while ev and attempt:
if attempt<retry: if attempt<retry:
self.logger.info("%d transient errors, retrying (%d to go)" % (len(ev), attempt)) self.logger.info("%d transient errors, retrying (%d to go)" % (len(ev), attempt))
sleep(pause or self.pause) time.sleep(pause or self.pause)
res = self.send_events_chunked(ev) res = self.send_events_chunked(ev)
attempt -= 1 attempt -= 1
...@@ -579,6 +578,16 @@ class Client(object): ...@@ -579,6 +578,16 @@ class Client(object):
def format_timestamp(epoch=None, utcoffset=None):
t = epoch if epoch else time.time()
tstr = "%04d-%02d-%02dT%02d:%02d:%02d" % time.localtime(t)[:6]
us = int(t % 1 * 1000000 + 0.5)
usstr = "." + str(us).rstrip("0") if us else ""
offset = utcoffset if utcoffset is not None else -(time.altzone if time.daylight else time.timezone)
offsstr = ("%+03d:%02d" % divmod((offset+30)//60, 60)) if offset else "Z"
return tstr + usstr + offsstr
def read_cfg(cfgfile): def read_cfg(cfgfile):
abspath = path.join(path.dirname(__file__), cfgfile) abspath = path.join(path.dirname(__file__), cfgfile)
with open(abspath, "r") as f: with open(abspath, "r") as f:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment