Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:17:32+00:00 2026-05-23T05:17:32+00:00

I want to open a new log file each a program runs, so I

  • 0

I want to open a new log file each a program runs, so I create a filename with the current time.

FILE * fplog;

void OpenLog()
{
    boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
    char buf[256];
    sprintf(buf,"ecrew%d%02d%02d_%02d%02d%02d.log",
        now.date().year(),now.date().month(),now.date().day(),
        now.time_of_day().hours(),now.time_of_day().minutes(),now.time_of_day().seconds()); 
    fplog = fopen(buf,"w");

}

This works perfectly in a debug build, producing files with names such as

ecrew20110309_141506.log

However the same code fails strangely in a release build

ecrew198619589827196617_141338.log

BTW, this also fails in the same way:

boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
char buf[256];

boost::gregorian::date day (boost::gregorian::day_clock::local_day());

sprintf(buf,"ecrew%d%02d%02d_%02d%02d%02d.log",
    day.year(),day.month(),day.day(),
now.time_of_day().hours(),now.time_of_day().minutes(),now.time_of_day().seconds()); 

fplog = fopen(buf,"w");

This works:

boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
char buf[256];
sprintf(buf,"ecrew%s_%02d%02d%02d.log",
    to_iso_string( boost::gregorian::day_clock::local_day() ).c_str(),
    now.time_of_day().hours(),now.time_of_day().minutes(),now.time_of_day().seconds()); 
fplog = fopen(buf,"w");

I’d still be curious why the previous two version fail in release build, but work in debug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:17:33+00:00Added an answer on May 23, 2026 at 5:17 am

    Okay I’m a bit late but as I stumbled on to your question when looking for the answer myself ( day_clock::local_day() gives weird results when compiled as Release, here on Win XP + Boost 1.46 ) ,
    I thought I should come back with what worked for me.

    The data seems to be stocked (I just use year, month and day) in a 16 bit manner but when you read them you get a 32 bit integer and whatever bug there is, it writes garbage into the top bits or it doesn’t clean ’em out before writing to the lower bytes.

    So my workaround is just to zero out the topmost 16 bits:

    date todaysdate(day_clock::local_day());
    int year = todaysdate.year() & 0xFFFF;
    

    instead of say:

    date todaysdate(day_clock::local_day());
    int year = todaysdate.year();
    

    and it works well for me anyway.

    Valmond

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to open a save file dialog, have the user enter a filename,
I want to be able to click a button and open a new form
I've opened a new window with window.open() and I want to use the reference
I want to open a file for reading, the C++ way. I need to
I want to open a folder window, in the appropriate file manager, from within
I want to open a file dialog box in user control. I used using
I want to open a file from a Class in C# using a Process,
I open a txt file on my server, get the Int and want to
Is there a way to do this: this.logFile = File.Open(what_r_u_doing.log, FileMode.OpenOrCreate, FileAccess.ReadWrite); using(var sr
I want to monitor a log file of our PBX for changes. I made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.