Overview
Features
Download
Documentation
Community
Add-Ons & Services

Rotation tag with incorrect hour

Please post support and help requests here.

Rotation tag with incorrect hour

Postby pcaetano » 27 Jun 2012, 20:21

Hallo.

I've setup a simple example using Poco::FileChannel, on which I call setProperty("rotation", "daily"). To test the rotation, I'm testing a scenario where the log file doesn't exist.

However, the hour on the rotation tag is incorrect (the hour on the log entry is correct):
# Log file created/rotated Wednesday, 27 Jun 12 18:12:03 GMT
2012-06-27 19:12:03.287 [Information] [test_logger][../Tests/main_logger_basic.cpp:27] Just getting started

From what I could gather, the problem (assuming I'm not doing anything wrong) seems to be here (file RotateStrategy.cpp):
Code: Select all
bool RotateByIntervalStrategy::mustRotate(LogFile* pFile)
(...)
      else
      {
            _lastRotate.update();
            std::string tag(ROTATE_TEXT);
            DateTimeFormatter::append(tag, _lastRotate, DateTimeFormat::RFC1036_FORMAT);
            pFile->write(tag);
      }
(...)

I see nothing here that checks/uses local time. Is this by design? An oversight? Or am I doing anything wrong?

My test code follows:
Code: Select all
#include "Poco/Logger.h"
#include "Poco/FileChannel.h"
#include "Poco/FormattingChannel.h"
#include "Poco/PatternFormatter.h"
#include "Poco/AutoPtr.h"

int main(int argc, char *argv[])
{
    Poco::Logger& l = Poco::Logger::get("test_logger");
    Poco::AutoPtr <Poco::FormattingChannel> f(new Poco::FormattingChannel(new
        Poco::PatternFormatter("%Y-%m-%d %H:%M:%S.%i [%p] [%s][%U:%u] %t")));
    f->getFormatter()->setProperty("times", "local");

    Poco::AutoPtr<Poco::FileChannel> fc(new Poco::FileChannel());
    fc->setProperty("path", "teste.log");
    fc->setProperty("times", "local");
    fc->setProperty("rotation", "daily");
    fc->setProperty("archive", "timestamp");
    fc->setProperty("compress", "true");
    fc->setProperty("purgeAge", "3 days");

    l.setLevel(Poco::Message::PRIO_INFORMATION);

    f->setChannel(fc);
    l.setChannel(f);

    poco_information(l, "Just getting started");

}


TIA
Paulo Caetano
pcaetano
 
Posts: 5
Joined: 07 Jun 2012, 17:01
Location: Portugal

Re: Rotation tag with incorrect hour

Postby alex » 28 Jun 2012, 00:07

From the log file entries, it would look like your time is GMT + 1 ( for DST ? ). Is that the case?
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Rotation tag with incorrect hour

Postby pcaetano » 28 Jun 2012, 10:44

alex wrote:From the log file entries, it would look like your time is GMT + 1 ( for DST ? ). Is that the case?


Yes, it is GMT + DST.

From Windows Control Panel:
Timzone: (UTC) Dublin, Edinburgh, Lisbon, London
DST: DST ends on 28 October 2012 at 02:00. The clock is set to go back 1 hour at that time

This code...
Code: Select all
#include <iostream>

#include "Poco/Timestamp.h"
#include "Poco/DateTime.h"
#include "Poco/LocalDateTime.h"
#include "Poco/Timezone.h"

int main(int argc, char *argv[])
{
    Poco::Timestamp now;
    Poco::DateTime dt(now);
    Poco::LocalDateTime ldt(now);

    using namespace std;
    using Poco::Timezone;

    cout << "DateTime::hour: " << dt.hour() << endl;
    cout << "LocalDatetime::hour: " << ldt.hour() << endl;
    cout << "Timezone::dst: " << Timezone::dst() << endl;
    cout << "Timezone::dstName: " << Timezone::dstName() << endl;
    cout << "Timezone::isDst: " << (Timezone::isDst(now) ? "true" : "false") << endl;
    cout << "Timezone::name: " << Timezone::name() << endl;
    cout << "Timezone::standardName: " << Timezone::standardName() << endl;
    cout << "Timezone::tzd: " << Timezone::tzd() << endl;
    cout << "Timezone::utcOffset: " << Timezone::utcOffset() << endl;
}


...gives this output
Code: Select all
DateTime::hour: 8
LocalDatetime::hour: 9
Timezone::dst: 3600
Timezone::dstName: GMT Daylight Time
Timezone::isDst: true
Timezone::name: GMT Daylight Time
Timezone::standardName: GMT Standard Time
Timezone::tzd: 3600
Timezone::utcOffset: 0


TIA.
Paulo Caetano
pcaetano
 
Posts: 5
Joined: 07 Jun 2012, 17:01
Location: Portugal

Re: Rotation tag with incorrect hour

Postby alex » 28 Jun 2012, 12:33

pcaetano wrote:I see nothing here that checks/uses local time. Is this by design? An oversight? Or am I doing anything wrong?

You are setting local time explicitly for log entries:
Code: Select all
fc->setProperty("times", "local");
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Rotation tag with incorrect hour

Postby pcaetano » 28 Jun 2012, 12:50

alex wrote:You are setting local time explicitly for log entries:
Code: Select all
fc->setProperty("times", "local");


Right. And, as I mentioned, that time is correct, i.e., it matches my actual time (This line was written at 19:12):
2012-06-27 19:12:03.287 [Information] [test_logger][../Tests/main_logger_basic.cpp:27] Just getting started

It's this time that is incorrect (also written at 19:12):
# Log file created/rotated Wednesday, 27 Jun 12 18:12:03 GMT

From the second example I've sent (example run at 09:xx):
DateTime::hour: 8
LocalDatetime::hour: 9

The first line is incorrect, the second is correct.

So, I know I only get the correct time when I use "local", hence my original question: The rotation tag doesn't seem to be using local time. Is this by design, and I should just live with it? Is it an oversight, something to be corrected in a future release? Or am I doing anything wrong, and there's actually some other setting/option I shoud be using?
pcaetano
 
Posts: 5
Joined: 07 Jun 2012, 17:01
Location: Portugal

Re: Rotation tag with incorrect hour

Postby alex » 28 Jun 2012, 13:40

pcaetano wrote:The first line is incorrect, the second is correct.

The beginning of wisdom is to call things by their right names - it may not be what you'd prefer to see, but it is not incorrect; it clearly states that it is GMT.
pcaetano wrote:So, I know I only get the correct time when I use "local", hence my original question: The rotation tag doesn't seem to be using local time. Is this by design, and I should just live with it? Is it an oversight, something to be corrected in a future release? Or am I doing anything wrong, and there's actually some other setting/option I shoud be using?

The rotation tag at the beginning of file is a workaround for impossibility of accurate file creation determination on some platforms. See this tracker item for details. If you would like it to be (optionally) in local time, propose a patch and we'll take it into consideration.
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Rotation tag with incorrect hour

Postby pcaetano » 28 Jun 2012, 14:06

alex wrote:The beginning of wisdom is to call things by their right names - it may not be what you'd prefer to see, but it is not incorrect; it clearly states that it is GMT.


Yes, you're right. I did state my definition of "correct" ("i.e., it matches my actual time"), but I could've put it in a more explicit fashion. Point taken.

alex wrote:The rotation tag at the beginning of file is a workaround for impossibility of accurate file creation determination on some platforms. See this tracker item for details. If you would like it to be (optionally) in local time, propose a patch and we'll take it into consideration.


Ok, I'll give it a try.

Thanks.
Paulo Caetano
pcaetano
 
Posts: 5
Joined: 07 Jun 2012, 17:01
Location: Portugal

Re: Rotation tag with incorrect hour

Postby pcaetano » 28 Jun 2012, 19:49

Hallo.

I've finished my first shot at it.

How would you like me to send it? Should I post the patch here, as an attachment?

Thanks.
Paulo Caetano
pcaetano
 
Posts: 5
Joined: 07 Jun 2012, 17:01
Location: Portugal

Re: Rotation tag with incorrect hour

Postby alex » 28 Jun 2012, 21:04

alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron