How can I format the date as epoch timestamp in logback? - logback

I am using logback and I want to print an epoch timestamp instead of the date and time.
https://logback.qos.ch/manual/layouts.html#contextName references https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html where there is no way to format a date as epoch.
I can't believe this essential functionality isn't available, but I googled for a while and couldn't find it.
What I found is the same question for log4j log4j : current time in milliseconds, but what #thegeko suggests there %d{UNIX_MILLIS} doesn't work for me in logback.
Does anybody know?

You can use this snippet to print Unix Epoch:
<layout class="net.logstash.logback.layout.LogstashLayout">
<timeZone>UTC</timeZone>
<timestampPattern>[UNIX_TIMESTAMP_AS_NUMBER]</timestampPattern>
</layout>
Reference: https://github.com/logstash/logstash-logback-encoder#customizing-timestamp

Related

How to get the current time in UTC?

I'm trying to get the current time in UTC in a UWP application. This should be a simple matter of constructing a DateTime object
DateTime const now{ clock::now() };
and accessing its UniversalTime field. However, that field does not appear to have been projected into C++/WinRT.
How do I get the current time in UTC using C++/WinRT?
Looks like a documentation bug. That field doesn't exist in C++/WinRT. Instead, DateTime is projected as a std::chrono::time_point. But similar to C++/CX, the documentation for the struct (not the field) is still somewhat accurat - it has the same granularity as FILETIME. But even easier than extracting the value youself, winrt::clock provides static methods to_file_time and to_time_t that convert DateTime to
FILETIME or time_t, respectively.
I'll get the documentation fixed up, and I've been meaning to write a blog post about how C++/WinRT seamlessly interops with std::chrono for timekeeping. I'm a a fan of std::chrono, and incorporating it into C++/WinRT was my idea, so the haters know who to blame. :)

MediaWiki: Convert seconds to HH:MM:SS

How do I convert seconds to HH.MM:SS via MediaWiki (plus Semantic Media Wiki)?
I tried and tried and just can't find a way.
The duration in seconds comes via filling out a template.
As I can't install more extensions to the Wiki the only ways are via SMW and parser functions.
Thank you very much in advance!
You should be able to do this with the time parser function:
{{#time: H.i.s | #123 }}
It't not strickly treating it as a time duration, but rather a time from the unix epoch, but if you don't go over 24 hours it doesn't really matter.
If you need to go higher, then you can build up a custom expression using the trunc operator, for example to get the number of hours:
{{#expr: trunc (123/60/60) }}

Make logback in SL4J show relative time (%r) in hours, minutes and seconds

I know that %r in logback outputs the relative time from the start of the logging event in milliseconds. How can I set it in a pattern like HH.mm.ss.SSS?
Unfortunately, something along the lines of %r{HH.mm.ss.SSS} (which is the way I do it for the current date/time %d) doesn't work. I can of course build a StopWatch object and manually output its value every time I call the logger, but this way seems rather unpractical.

Error in subscribeContext

I'm currently trying to configure the Fiware Iot Broker with the Configuration Manager (NECongMan) and Fiware Orion as the context producer. I'm having a problem with the NGSI10 subscribeContext operation.
This is the request sent to the IoT Broker:
<?xml version="1.0"?>
<subscribeContextRequest>
<entityIdList>
<entityId type="Room" isPattern="false">
<id>Room1</id>
</entityId>
</entityIdList>
<attributeList>
<attribute>temperature</attribute>
</attributeList>
<reference>http://localhost:1028/accumulate</reference>
<duration>PT1H</duration>
<notifyConditions>
<notifyCondition>
<type>ONCHANGE</type>
<condValueList>
<condValue>pressure</condValue>
</condValueList>
</notifyCondition>
</notifyConditions>
<throttling>PT5S</throttling>
</subscribeContextRequest>
The IoTBroker tries to contact Orion issuing a subscribeContextRequest but the duration string is changed:
<subscribeContextRequest>
<entityIdList>
<entityId
type="Room"
isPattern="false">
<id>
Room1
</id>
</entityId>
</entityIdList>
<attributeList>
<attribute>
temperature
</attribute>
</attributeList>
<reference>
http://192.168.16.178:8080/ngsi10/notify
</reference>
<duration>
P0Y0M0DT0H59M58.157S
</duration>
<notifyConditions>
<notifyCondition>
<type>
ONCHANGE
</type>
<condValueList>
<condValue>
pressure
</condValue>
</condValueList>
</notifyCondition>
</notifyConditions>
<throttling>
PT5S
</throttling>
</subscribeContextRequest>
But Orion gives an error (invalid payload: syntax error in duration string). Do you have any idea how to resolve the issue?
For one hour, Duration parameter may be P1H instead of PT1H, according to the ISO 8601 standard format, it seems like PT is used only to avoid ambiguity between P1M for one month and PT1M for one minute.
Hope it helps
Orion 0.26.1 (the last version in the moment of writing this) doesn't support decimal values (as 58.157) for seconds in duration strings. We have created an issue about that and our plan is to have it solved by next release (0.27.0).
Not sure if modifying the way IoTBroker behaves (in order to round up/down the secons to an integer in the request it sends to Orion) would be a valid workaround... I don't know the details about IoTBroker.
EDIT: the fix to support decimal fractions in the seconds field has been just implemented in Orion in develop branch, so it will be available in the next Orion version (0.27.0). Alternatively, you could download source code and build the code to get the fix right now.

What is such a thing called?

I want to know if there is a name for a function/method/library that converts a given date object with time information into something like:
a few seconds ago
2 minutes ago
about an hour ago
10 hours ago
yesterday
on 12-May-2010
and so on. I don't know what to google for, but I'm guessing that someone must have done this before. I'm specifically looking for an implementation in python (preferably a Django filter) that works on a datetime, but any open source implementation in any language will do really, for inspiration.
Google for "Fuzzy Date Time"
I believe it is called "fuzzy timestamp" (also "timedelta")
ruby and python examples are available in this SO question
git has its own date.c utility source for this kind of refspec date specification.
A ref followed by the suffix # with a date specification enclosed in a brace pair (e.g. {yesterday}, {1 month 2 weeks 3 days 1 hour 1 second ago} or {1979-02-26 18:30:00}) to specify the value of the ref at a prior point in time.
I don't really know the name of the method used, but you can find a Javascript implementation of what you're describing at DateJS.