Logging to a file

Here we speak about Code and Design.
Post Reply
Posts: 24
Joined: Sun Apr 20, 2008 2:40 am

Post by starkravingmad » Thu Nov 09, 2006 3:33 pm

Since the buffer on the console can fill up quickly, you can't always
find the output message you are looking for. So following some of the
examples from the ACE library, I changed some code to enable logging
the output to a file.

#include "ace/OS_main.h" //Included to enable file logging
#include "ace/streams.h" //Included to enable file logging

Then change the line that reads:

// Lets setup logging to a file inaddtion to logging to the console
ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

// Create a persistent store.
const char *filename = "output.log";
ofstream myostream (filename, ios::out | ios::trunc);

// Check for errors.
if (myostream.bad ())
return 1;

// Set the ostream.
ACE_LOG_MSG->msg_ostream (&myostream);


This will create/overwrite a file called "output.log" in your [b:a1ee564769]debug[/b:a1ee564769] folder
everytime you run the server. To get the most out of (or into) the log file some
other changes need to be made.

In the last 2 function declarations comment out the
cout statemtents and put in ACE_DEBUG statements as follows:
char VersionInfo::getAuthVersion(void) const
//cout << VersionString; commented out
ACE_DEBUG ((LM_INFO, VersionString)); //Will print to console and file
return 0;

char VersionInfo::getCopyright(void) const
//cout << CopyrightString; commented out
ACE_DEBUG ((LM_INFO, CopyrightString)); //Will print to console and file
return 0;

While we are at it, we may as well change the database connection strings to log to file.

In the [b:a1ee564769]Database::OpenConnection[/b:a1ee564769] function change the [b:a1ee564769]printf[/b:a1ee564769] statement
printf("Connected to PostgreSQL database server version %i.\\n",
PQserverVersion(pConnection)); // Print server version
ACE_DEBUG ((LM_INFO,"Connected to %s database server version %i.\\n",
PQdb(pConnection), PQserverVersion(pConnection)));


I changed the message so that instead of getting 2 identical lines of
[b:a1ee564769]"Connected to PostgreSQL database server version 80104."[/b:a1ee564769]
you should now see
[b:a1ee564769]"Connected to cohemu database server version 80104."
"Connected to cohemu_game database server version 80104."[/b:a1ee564769]

Posts: 15
Joined: Sat Oct 28, 2006 6:34 pm

Post by calsmurf2904 » Fri Nov 10, 2006 6:49 am

You are good with your fast fixes keep up the good work :D

User avatar
Posts: 397
Joined: Thu Jan 10, 2013 3:40 pm

Post by nemerle » Mon Nov 13, 2006 7:08 am

Thank you, your fixes are now in the svn. If it is not a big hurdle, could you post in the patches forum please ? :)
If you ever need to post a bigger patch i'd advise you to use a .patch/.diff format. It will help us apply it to the codebase. Oh and I'm sorry you had to wait so long before seeing your code in the repository.
"Ich was in one sumere dale,
in one suthe diyhele hale,
iherde ich holde grete tale
an hule and one niyhtingale."

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest