Logging to a file

Here we speak about Code and Design.
Post Reply
starkravingmad
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.


[color=blue:a1ee564769]root/AuthServer/src/main.cpp[/size:a1ee564769][/color:a1ee564769]
[code:1:a1ee564769]
#include "ace/OS_main.h" //Included to enable file logging
#include "ace/streams.h" //Included to enable file logging
[/code:1:a1ee564769]

Then change the line that reads:
FROM
[code:1:a1ee564769]
ACE_LOG_MSG->priority_mask (LM_DEBUG |LM_ERROR | LM_WARNING,
ACE_Log_Msg::PROCESS);
[/code:1:a1ee564769]
TO
[code:1:a1ee564769]
ACE_LOG_MSG->priority_mask (LM_DEBUG |LM_ERROR | LM_WARNING | LM_INFO,
ACE_Log_Msg::PROCESS);

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

// 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);
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */

[/code:1:a1ee564769]

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.

[color=blue:a1ee564769]root/Common/include/version.h[/size:a1ee564769][/color:a1ee564769]
In the last 2 function declarations comment out the
cout statemtents and put in ACE_DEBUG statements as follows:
[code:1:a1ee564769]
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;
}
[/code:1:a1ee564769]

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

[color=blue:a1ee564769]root/Common/src/database.cpp[/size:a1ee564769][/color:a1ee564769]
In the [b:a1ee564769]Database::OpenConnection[/b:a1ee564769] function change the [b:a1ee564769]printf[/b:a1ee564769] statement
FROM:
[code:1:a1ee564769]
printf("Connected to PostgreSQL database server version %i.\\n",
PQserverVersion(pConnection)); // Print server version
}
[/code:1:a1ee564769]
TO:
[code:1:a1ee564769]
ACE_DEBUG ((LM_INFO,"Connected to %s database server version %i.\\n",
PQdb(pConnection), PQserverVersion(pConnection)));

[/code:1:a1ee564769]

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]

calsmurf2904
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
nemerle
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 3 guests