Printing the timestamp miliseconds in R does not work -
i have application logs info in r. using logging library that. problem timestamp has no milliseconds, , not order of logs. in logging file, r puts logs in right order, use logstash , es having history , monitoring. because timestamp got not right order of logs, add milliseconds.
i have tried use strptime , %os(n), seems not work. if add %os, na simple things:
strptime(sys.time(), "%h:%m:%os") i have seen there more posts this, no answer, posting here, too.
i have use r 3.2.0 under linux ubuntu 14.04. how solve it? how have milliseconds in timestamp?
ok, after using strftime, getting milliseconds, seems 0.
i have log formater:
logformatter <- function(record) { sprintf('application(%s) %s [%s] [] %s - %s', format(as.hexmode(sys.getpid()), width = 8), record$levelname, strftime(record$timestamp, "%y-%m-%dt%h:%m:%os3"), record$logger, record$msg) } i have added logger:
addhandler(writetofile, logger = "mylogger", file = "/var/log/application/logs.log", level = 'info', formatter = logformatter) and log this:
loginfo("some info x", logger = mylogger) but output seems @ beginning of second:
application(000018f3) info [2015-09-21t11:45:56.000] [] info 1 application(000018f3) info [2015-09-21t11:45:58.000] [] info 2 application(000018f3) info [2015-09-21t11:45:58.000] [] info 3 application(000018f3) info [2015-09-21t11:45:58.000] [] info 4 application(000018f3) info [2015-09-21t11:45:59.000] [] info 5
to obtain millisecond information helpful set
options(digits.secs = 3) this give, instance
> strptime(sys.time(), format = "%y-%m-%d %h:%m:%os") #[1] "2015-09-21 11:52:09.787 cest" maybe helps in case.
Comments
Post a Comment