m (→The header) |
(Radical changes in the step 4, new theme) |
||
| Line 1: | Line 1: | ||
[[Category:Tutorial]] | [[Category:Tutorial]] | ||
| - | = Step Four: : | + | = Step Four: : Setup the logging system = |
== Introduction == | == Introduction == | ||
| - | + | The ''Crystal Space SDK '' contents a built-in reporter system. You can sending messages to the following places: | |
| - | + | * stdout : Your message will be sent to the standard output. | |
| + | * stderr : Your message will be sent to standard error channel. | ||
| + | * alert : Your message will be displayed in a information window. | ||
| + | * console: Your message will be displayed on the console output. | ||
| + | * debug : Your massage will be logged into the debug log file. | ||
| + | * popup : | ||
| - | + | ==Adding some log-related config options == | |
| - | + | Let's create an optional log file. First, we add to our ''cim.cfg'' the following options: | |
| - | + | Cim.Settings.EnableLogging = true; | |
| + | Cim.Settings.DebugFileName = /cim/debug.log | ||
| + | Cim.Settings.AppendLogFile = false | ||
| + | When the ''EnableLogging'' option is true, the game writes the report messages in the log file. The ''DebugFileName'' decides the name of the log file. The ''AppendLogFile '' option controls, the app creates a new log file or appends the messages to the old one (if any). | ||
| + | |||
| + | Ok, let's go to load this options in the ''cimGame::LoadConfig()'': | ||
<pre> | <pre> | ||
| - | + | bool cimGame::LoadConfig() | |
| - | + | { | |
| - | + | csRef<iConfigManager> confman (CS_QUERY_REGISTRY (GetObjectRegistry(), iConfigManager)); | |
| - | + | startmap = confman->GetStr("Cim.Settings.StartLevel","terrain"); | |
| - | + | use_console = confman->GetBool("Cim.Settings.EnableConsole",false); | |
| - | + | enable_logging = confman->GetBool("Cim.Settings.EnableLogging",false); | |
| - | + | debug_filename = confman->GetStr("Cim.Settings.DebugFileName","/cim/debug.log"); | |
| + | append_logfile = confman->GetBool("Cim.Settings.AppendLogFile",true); | ||
| + | return true; | ||
| + | } | ||
</pre> | </pre> | ||
| - | Don't forget to link the CEGUIBase* library, when you build this demo. The correct name is depend on your build system. When you use '''MSVC8''', you need ''CEGUIBase-vc8_d.lib'' (in debug mode) or ''CEGUIBase-vc8.lib '' in release mode. These are in your ''CS\libs\csutil\win32\libs'' folder. | ||
| + | == Listening the reports == | ||
| - | + | ''Crystal Space '' provides us the ''iStandardReporterListener'' interface to do this. Let's query this: | |
| - | + | ||
| - | + | ||
<pre> | <pre> | ||
| - | + | listener = CS_QUERY_REGISTRY(GetObjectRegistry(),iStandardReporterListener); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
</pre> | </pre> | ||
| - | + | Ok, we have a the listener, let's customize it. As we said, Crystal Space ensures you many channel to your reports. Crystal Space uses 5 severity level: | |
| - | + | * CS_REPORTER_SEVERITY_BUG: his is the worst thing that can happen. It means that some code detected a bug in Crystal Space. | |
| + | * CS_REPORTER_SEVERITY_ERROR: There was an error of some kind. Usually this is an error while reading data. | ||
| + | * CS_REPORTER_SEVERITY_WARNING: There was some condition which is non fatal but is suspicious. | ||
| - | * | + | * CS_REPORTER_SEVERITY_NOTIFY: This is for debugging and it will usually generate an entry in some log. |
| - | + | ||
| - | + | ||
| - | + | We can define, on what messaging channel listening what severity levels. | |
| + | iStandardReporterLIstener has a SetMessageDestination function: | ||
<pre> | <pre> | ||
| - | + | virtual void SetMessageDestination (int severity, | |
| - | + | bool do_stdout, bool do_stderr, bool do_console, | |
| - | + | bool do_alert, bool do_debug, bool do_popup = false) = 0; | |
| - | + | ||
| - | bool | + | |
</pre> | </pre> | ||
| - | + | ||
| + | We want to use the ''standard output'', the ''console'' and the ''debug file''. So the code is: | ||
<pre> | <pre> | ||
| - | + | listener->SetMessageDestination(CS_REPORTER_SEVERITY_ERROR,true,false,true,false,true,false); | |
| - | + | listener->SetMessageDestination(CS_REPORTER_SEVERITY_WARNING,true,false,true,false,true,false); | |
| - | + | listener->SetMessageDestination(CS_REPORTER_SEVERITY_NOTIFY,true,false,true,false,true,false); | |
| - | + | listener->SetMessageDestination(CS_REPORTER_SEVERITY_DEBUG,true,false,true,false,true,false); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
</pre> | </pre> | ||
| - | We need an event handler to subscribe to the PostProcess event. We will render cegui in this phase. The solution is same, as in the prvious tutorial. | ||
| + | Now we set up the log filename: | ||
<pre> | <pre> | ||
| - | + | listener->SetDebugFile(debug_filename,append_logfile); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
</pre> | </pre> | ||
| - | These are the window callback functions. Ehen the user will push a button on the cegui layout, the corresponding function will be called. Important, that all CEGUI callback function must foloww the following definition: | ||
| - | |||
| - | <pre>bool MyCEGUIEventHandler(const CEGUI::EventArgs&);</pre> | ||
| + | ==Time stamps == | ||
| + | Current date and time is not so important in 3D apps, but a coll looking log file contents the starting time at least in a headline. We write the current date and time into string, using the _strdate and _strtime functions (you have to include "time.h" : | ||
<pre> | <pre> | ||
| - | + | char dateStr [9]; | |
| - | + | char timeStr [9]; | |
| - | + | _strdate( dateStr); | |
| - | + | _strtime( timeStr ); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
</pre> | </pre> | ||
| - | + | Ok, now we create a head line, using the date and time info: | |
| - | + | ||
| - | + | ||
<pre> | <pre> | ||
| - | + | csString logStr("---------------------------------------"); | |
| - | + | logStr+="\n"; | |
| - | + | logStr+="Cim started at "; | |
| - | + | logStr+=dateStr; | |
| - | + | logStr+=" : "; | |
| - | + | logStr+=timeStr; | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | csReporterHelper::Report(GetObjectRegistry(),CS_REPORTER_SEVERITY_NOTIFY,"cim",logStr.GetData()); | |
} | } | ||
| - | |||
| - | FinalProcess = csevPostProcess (object_reg); | ||
</pre> | </pre> | ||
| - | + | Calling the csReporterHelper::Report (or the csReport macro) the head line goes to the log file. | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | That's it. See the code for all changes. Get the sources from [http://www.crystaldoc.atw.hu/src/cim/step4.zip here] | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | [[Tutorials|Tutorial Home]] | |
Revision as of 14:21, 20 July 2008
Contents |
Step Four: : Setup the logging system
Introduction
The Crystal Space SDK contents a built-in reporter system. You can sending messages to the following places:
- stdout : Your message will be sent to the standard output.
- stderr : Your message will be sent to standard error channel.
- alert : Your message will be displayed in a information window.
- console: Your message will be displayed on the console output.
- debug : Your massage will be logged into the debug log file.
- popup :
Adding some log-related config options
Let's create an optional log file. First, we add to our cim.cfg the following options:
Cim.Settings.EnableLogging = true; Cim.Settings.DebugFileName = /cim/debug.log Cim.Settings.AppendLogFile = false
When the EnableLogging option is true, the game writes the report messages in the log file. The DebugFileName decides the name of the log file. The AppendLogFile option controls, the app creates a new log file or appends the messages to the old one (if any).
Ok, let's go to load this options in the cimGame::LoadConfig():
bool cimGame::LoadConfig()
{
csRef<iConfigManager> confman (CS_QUERY_REGISTRY (GetObjectRegistry(), iConfigManager));
startmap = confman->GetStr("Cim.Settings.StartLevel","terrain");
use_console = confman->GetBool("Cim.Settings.EnableConsole",false);
enable_logging = confman->GetBool("Cim.Settings.EnableLogging",false);
debug_filename = confman->GetStr("Cim.Settings.DebugFileName","/cim/debug.log");
append_logfile = confman->GetBool("Cim.Settings.AppendLogFile",true);
return true;
}
Listening the reports
Crystal Space provides us the iStandardReporterListener interface to do this. Let's query this:
listener = CS_QUERY_REGISTRY(GetObjectRegistry(),iStandardReporterListener);
Ok, we have a the listener, let's customize it. As we said, Crystal Space ensures you many channel to your reports. Crystal Space uses 5 severity level:
- CS_REPORTER_SEVERITY_BUG: his is the worst thing that can happen. It means that some code detected a bug in Crystal Space.
- CS_REPORTER_SEVERITY_ERROR: There was an error of some kind. Usually this is an error while reading data.
- CS_REPORTER_SEVERITY_WARNING: There was some condition which is non fatal but is suspicious.
- CS_REPORTER_SEVERITY_NOTIFY: This is for debugging and it will usually generate an entry in some log.
We can define, on what messaging channel listening what severity levels. iStandardReporterLIstener has a SetMessageDestination function:
virtual void SetMessageDestination (int severity, bool do_stdout, bool do_stderr, bool do_console, bool do_alert, bool do_debug, bool do_popup = false) = 0;
We want to use the standard output, the console and the debug file. So the code is:
listener->SetMessageDestination(CS_REPORTER_SEVERITY_ERROR,true,false,true,false,true,false); listener->SetMessageDestination(CS_REPORTER_SEVERITY_WARNING,true,false,true,false,true,false); listener->SetMessageDestination(CS_REPORTER_SEVERITY_NOTIFY,true,false,true,false,true,false); listener->SetMessageDestination(CS_REPORTER_SEVERITY_DEBUG,true,false,true,false,true,false);
Now we set up the log filename:
listener->SetDebugFile(debug_filename,append_logfile);
Time stamps
Current date and time is not so important in 3D apps, but a coll looking log file contents the starting time at least in a headline. We write the current date and time into string, using the _strdate and _strtime functions (you have to include "time.h" :
char dateStr [9]; char timeStr [9]; _strdate( dateStr); _strtime( timeStr );
Ok, now we create a head line, using the date and time info:
csString logStr("---------------------------------------");
logStr+="\n";
logStr+="Cim started at ";
logStr+=dateStr;
logStr+=" : ";
logStr+=timeStr;
csReporterHelper::Report(GetObjectRegistry(),CS_REPORTER_SEVERITY_NOTIFY,"cim",logStr.GetData());
}
Calling the csReporterHelper::Report (or the csReport macro) the head line goes to the log file.
That's it. See the code for all changes. Get the sources from here
