Logs

[ LiB ]

Right now I'm going to sidestep the main path of this chapter to tell you about the log classes. SimpleMUD has two text logs: the user log, and the error log. I showed you the logging capabilities in Chapter 4, "The Basic Library," using the BasicLib::Logger class, and the text-file version named BasicLib::TextLog . SimpleMUD uses global text logs. The definitions for them can be found in the files Demos\Chapter08\Demo08-01\SimpleMUD\SimpleMUDLogs.h and .cpp.

Because the logs are meant to be globals , I need to declare them as extern in the header file like this:

 extern TextLog ERRORLOG; extern TextLog USERLOG; 

Any part of your program that uses these files can include the .h file, and you can use either of the logs that you like.

However, you still need to construct the logs somewhere, so this is done in the .cpp file:

 TextLog ERRORLOG( "logs/errors.log", "Error Log", true, true ); TextLog USERLOG( "logs/users.log", "User Log", true, true ); 

Remember the parameters for the constructor. The first parameter is the file name of the log, the second is the name of the log, and the two Booleans determine if you want to datestamp and timestamp every entry in the log. As you can see from the previous code segment, the logs are stored in a subdirectory named "logs", and the files are named "errors.log" and "users.log".

Whenever errors occur in the game, it is advisable to log them to the error log, and user actions such as logging on and off should be logged into the user log.

[ LiB ]


MUD Game Programming
MUD Game Programming (Premier Press Game Development)
ISBN: 1592000908
EAN: 2147483647
Year: 2003
Pages: 147
Authors: Ron Penton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net