Jump to content
Sign in to follow this  
  • entries
    73
  • comments
    131
  • views
    55059

Logger

Sign in to follow this  
okonomiyaki

316 views

Today's chunk of code (ok, second one) segment introduces the...

Logger
.h

/* --------------------------------------------------------------
File: AXLogger.h
Description: This file defines a class that logs messages. Depending on the type of message,
it logs it to the appropriate output.
For now, it logs everything to both the console and the file. I think it's important
to separate the types of messages, however, so later I can come back and change the type of
outputs for each type of message.

You specify the type of message by passing in MESSAGE_USER, MESSAGE_APP, or MESSAGE_SYSTEM
when you write the message. A line with the type of message, calling function, and message
will appear in the appropriate output. You are allowed printf style formatting.
Date: June 29, 2005
Author: James Long
-------------------------------------------------------------- */



#if !defined(AXLOGGER_INCLUDE)
#define AXLOGGER_INCLUDE

// The different log types
enum LogType {
LOG_TYPE_USER = 1,
LOG_TYPE_APPLICATION = 2,
LOG_TYPE_SYSTEM = 4,
LOG_TYPE_DEBUG = 8
};

// Define some macros to make logging much easier
#define MESSAGE_USER LOG_TYPE_USER, __FUNCTION__
#define MESSAGE_APP LOG_TYPE_APPLICATION, __FUNCTION__
#define MESSAGE_SYS LOG_TYPE_SYSTEM, __FUNCTION__
#define MESSAGE_DBG LOG_TYPE_DEBUG, __FUNCTION__

class AXLogger : AXSingleton {
public:
AXLogger();
virtual ~AXLogger();

AXResult Initialize();
void Shutdown();

void Write(LogType target, const char* func, const char* msg, ...);

private:
char _Temp_Buf[5012];
ofstream _FileLog;
};


#endif




.cpp

/* --------------------------------------------------------------
File: AXLogger.cpp
Description: Implementation for the AXLogger class. See AXLogger.h for details.
Date: June 29, 2005
Author: James Long
-------------------------------------------------------------- */


#include "..\\AXCore.h"

AXLogger::AXLogger() : AXSingleton() {
}
AXLogger::~AXLogger() {
}

AXResult AXLogger::Initialize() {
// Open the log file
_FileLog.open("log.txt");
return AXSUCCESS;
}

void AXLogger::Shutdown() {
// Close the log file
_FileLog.close();
}

void AXLogger::Write(LogType target, const char *FunctionName, const char *Msg, ...) {
va_list args;

va_start(args, Msg);
vsprintf(_Temp_Buf, Msg, args);
va_end(args);

// Detect the log type and log accordingly (for now they basically do the same thing)
if(target & LOG_TYPE_USER) {
printf("\nAX User> *** %s *** \n\n", _Temp_Buf);
_FileLog << "\nAX User> *** " << _Temp_Buf << " *** \n\n";
}

if(target & LOG_TYPE_APPLICATION) {
printf("AX Application (%s)> %s\n", FunctionName, _Temp_Buf);
_FileLog << "AX Application (" << FunctionName << ")> " << _Temp_Buf << "\n";
}

if(target & LOG_TYPE_SYSTEM) {
printf("AX System (%s)> %s\n", FunctionName, _Temp_Buf);
_FileLog << "AX System (" << FunctionName << ")> " << _Temp_Buf << "\n";
}

if(target & LOG_TYPE_DEBUG) {
#ifdef _DEBUG
printf("*** AX Debug (%s)> %s\n", FunctionName, _Temp_Buf);
#endif
}

}


Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!