Show Log.cpp syntax highlighted
/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG *
*Copyright (C) 2006, Tony Sparks *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
#include "StdAfx.h"
#include "Log.h"
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <time.h>
Log::Log(void)
{
}
int Log::Init(const std::string &file)
{
m_output.open(file.c_str());
Write(-1, "Log started: \n");
return 0;
}
/**
* Write to the log file
*/
void Log::Write(int type, const char* s, ... )
{
static int counter = 0;
char buffer[1024];
va_list arguments;
va_start(arguments, s);
_vsnprintf_s(buffer, sizeof(buffer), s, arguments);
va_end(arguments);
/**
* Decide the alarm level
*/
std::string error;
switch( type )
{
case LOG_WARNING:
error = "WARNING: ";
break;
case LOG_DANGEROUS:
error = "DANGEROUS: ";
break;
case LOG_ERROR:
error = "ERROR--> ";
break;
default:
error = ": ";
break;
}
counter++;
std::cout << counter << ": " << buffer << std::endl;
m_output << counter << ": " << error << buffer << std::endl;
// m_output.flush();
}
See more files for this project here