GP2X Creating Log Files On The Gp2x


yaustar

UK GP32 & GP2X Owner
Joined
Oct 18, 2003
Messages
2,714
Location
UK
Website
Visit site
Currently I have a class to create a log file on Windows platform, but on the GP2X/Linux, it doesn't create one. Can anyone tell me the reason why?

Cheers

Code:
//! A class to write logs to a file

#ifndef LOGGER_H
#define LOGGER_H

#include <fstream>
#include <iostream>
#include <string>

namespace LogModule
{
	class Logger
	{
	private:
		//! Stream to the file
		std::ofstream _OutFileStream;

	public:
		//! Standard constructor. Clears the existing error log file and open the file
		/**
			\param Filename const string& to the file to be used
		*/
		Logger(const std::string &Filename)
		{
			std::cerr << "<< Opening Logfile " << Filename << " >>" << std::endl;
			// Open the file stream
			_OutFileStream.open(Filename.c_str() );

			// Check the stream
			if(_OutFileStream.fail() )
				std::cerr << "Error opening log file" << std::endl;

			_OutFileStream << "<< Opened Log File >>\n";
		}

		//! Standard Destructor. Closes the stream to the file
		~Logger(void)
		{
			std::cerr << "<< Closing File >>" << std::endl;
			_OutFileStream << "<< Closed Log File >>\n";
			// Close the file stream if it is open
			if(_OutFileStream.is_open() )
				_OutFileStream.close();
		}

		// Lots of operator overloads
		// TODO[2006-06-01]: Need a cleaner way of doing this
		//! Operator << overloader for strings and char*
		std::ostream& operator << (const std::string &OutString)
		{
			_OutFileStream << OutString;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for signed intergers
		std::ostream& operator << (const signed int &OutInt)
		{
			_OutFileStream << OutInt;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for unsigned intergers
		std::ostream& operator << (const unsigned int &OutInt)
		{
			_OutFileStream << OutInt;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for signed chars
		std::ostream& operator << (const signed char &OutChar)
		{
			_OutFileStream << OutChar;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for unsigned chars
		std::ostream& operator << (const unsigned char &OutChar)
		{
			_OutFileStream << OutChar;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for floats
		std::ostream& operator << (const float &OutFloat)
		{
			_OutFileStream << OutFloat;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		//! Operator << overloader for doubles
		std::ostream& operator << (const double &OutDouble)
		{
			_OutFileStream << OutDouble;
			_OutFileStream.flush();
			return _OutFileStream;
		}

		/*//! Operator << overloader for boolean
		std::ostream& operator << (const bool &OutBool)
		{
			_OutFileStream << OutBool;
			_OutFileStream.flush();
			return _OutFileStream;
		}*/
	};

	//! Global error log
	extern Logger ErrLog;
};

#endif // LOGGER_H

/*
History
=======
2006-06-01: Created a global error log file

2006-06-01: Created header and source file with code
*/
 
Erm.. it has now appeared on my GP2X for some strange reason.... :$

Sorry, my bad.. thanks for checking though...
 
Back
Top