haber5 0 Newbie Poster

Hi folks

I have a server written in C++ over ACE infrastructure. I'm using the ACE logging tools and here is how I create it in the main thread:

std::ofstream* output = new std::ofstream (name);
ACE_LOG_MSG->msg_ostream (output, 0);
ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

I'm working with a multithreaded system and logging is working great. Problem starts when I wish to replace my log file (after it reaches a certain size).

I tried the following:

// Lock out any other logging.
if (ACE_LOG_MSG->acquire() != 0)
{
	ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("checkLogFileSize() : ERROR -  
                                                                                Cannot acquire lock!\n")));
	return;
}
//Take old stream
std::ofstream* old_output = ACE_reinterpret_cast(std::ofstream*, 
                                                                          ACE_LOG_MSG->msg_ostream());	
	
//create new stream
ACE_TCHAR name[256];
sprintf(name, "%s.%d", debugLog, suffix++);
std::ofstream* new_output = new std::ofstream(name);
ACE_LOG_MSG->msg_ostream(new_output, 0);
// Release the lock previously acquired.
ACE_LOG_MSG->release();
//close and delete old stream
old_output->close();
delete old_output;

After the file is switched, I'm getting a sigmentation fault coming (I guess) from another instance of ACE_Log_Msg trying to write to the old file I have already deleted. Could you please advise both why isn't the above code change the file to all instances and what is the best way to do it?

10x a lot

Alon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.