ich hab leider nin compile Problem mit der Boost Logging Libray
Ich verwende den gcc compiler version 4.9 und Codeblocks 13.12 unter linux
boost version 1.54
Die compiler fehler treten z.b bei
Code:
sink->set_filter(boost::phoenix::bind(&DragonFiesta::Log::Log_Filter, severity.or_none(), tag_attr.or_none()));
Code:
sink->set_formatter(&DragonFiesta::Log::LogConsole);
sink->set_filter(boost::phoenix::bind(&Log::Log_Filter, severity.or_none(), tag_attr.or_none()));
Mein Code
Log.hpp
Code:
#ifndef LOG_H
#define LOG_H
#define BOOST_LOG_DYN_LINK
#include <boost/log/expressions/keyword.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/phoenix/bind.hpp>
#include <ostream>
namespace DragonFiesta
{
typedef boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > text_sink;
enum severity_level
{
DEBUG ,
WARNING,
INFO,
ERROR,
CRITICAL_ERROR
};
enum LogTag
{
DATABASE,
NETWORK ,
INTERNETWORK,
MAINLEVEL
};
typedef enum
{
CC_DARKGRAY = 0x0130,
CC_LIGHTRED = 0x0131,
CC_LIGHTGREEN = 0x0132,
CC_YELLOW = 0x0133,
CC_LIGHTBLUE = 0x0134,
CC_LIGHTMAGENTA = 0x0135,
CC_LIGHTCYAN = 0x0136,
CC_WHITE = 0x0137,
CC_BLACK = 0x2230,
CC_RED = 0x2231,
CC_GREEN = 0x2232,
CC_BROWN = 0x2233,
CC_BLUE = 0x2234,
CC_MAGENTA = 0x2235,
CC_CYAN = 0x2236,
CC_LIGHTGRAY = 0x2237
} CONSOLE_COLORS;
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level)
BOOST_LOG_ATTRIBUTE_KEYWORD(tag_attr, "Tag", std::string)
BOOST_LOG_ATTRIBUTE_KEYWORD(timestamp, "TimeStamp", boost::posix_time::ptime)
class Log
{
public:
Log();
virtual ~Log();
void Initialize(); //first initial console :D
bool Initialize(std::string filename);
bool SetupLogLevel(LogTag tag,int Level);
void LogMessage(severity_level Level,const char* format, ... );
void LogMessage(severity_level Level,LogTag Tag,const char* format, ... );
bool Log_Filter(boost::log::value_ref< DragonFiesta::severity_level, DragonFiesta::tag::severity > const& level,boost::log::value_ref< std::string, DragonFiesta::tag::tag_attr > const& tag);
protected:
private:
void SetConsoleColor( int textcolor, int backcolor = 0 );
void LogConsole(boost::log::record_view const& rec, boost::log::formatting_ostream& strm);
std::string LogDateString();
const char* Levelstrings[5] =
{
"DEBUG",
"WARNING",
"INFO",
"ERROR",
"CRITICAL_ERROR",
};
int LogLevels[4] =
{
0,//DATABASE
0,//NETWORK
0,//INTERNETWORK
0,//MainLevel
};
const char* Tagstrings[3] =
{
"DATABASE",
"NETWORK",
"INTER_NETWORK" ,
};
std::map<std::string,int> LogLevelColors =
{
{ "DEBUG", CC_LIGHTMAGENTA },
{ "WARNING", CC_YELLOW },
{ "INFO", CC_GREEN },
{ "ERROR", CC_LIGHTRED },
{ "CRITICAL_ERROR", CC_RED },
};
};
}
#endif // LOG_H
Log.cpp
Quote:
#include "Log.hpp"
#include <boost/log/expressions.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/attributes/scoped_attribute.hpp>
#include <boost/phoenix/bind.hpp>
#include <cstddef>
#include <string>
#include <ostream>
#include <fstream>
#include <iomanip>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/sources/basic_logger.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/attributes/scoped_attribute.hpp>
#include <boost/log/utility/value_ref.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
DragonFiesta::Log::Log()
{
//ctor
}
DragonFiesta::Log::~Log()
{
//dtor
}
void DragonFiesta::Log::Initialize()
{
//First Add Console Logging
boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >();
sink->set_formatter(&DragonFiesta::Log::LogConsole);
sink->set_filter(boost:hoenix::bind(&Log::Log_Filte r, severity.or_none(), tag_attr.or_none()));
boost::log::core::get()->add_sink(sink);
}
bool DragonFiesta::Log::Initialize(std::string filename)
{
try
{
boost::log::formatter fmt = boost::log::expressions::stream << "[" << DragonFiesta::Log::LogDateString() << "]"
<< boost::log::expressions::if_(boost::log::expressio ns::has_attr(DragonFiesta::tag_attr))
[
boost::log::expressions::stream << "[" << DragonFiesta::tag_attr << "]"
]
<< "[" << DragonFiesta::severity << "]: "
<< boost::log::expressions::smessage;
boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >();
sink->locked_backend()->add_stream(
boost::make_shared< std:fstream >(filename));
sink->set_formatter(fmt);
sink->set_filter(boost:hoenix::bind(&DragonFiesta::Lo g::Log_Filter, severity.or_none(), tag_attr.or_none()));
boost::log::core::get()->add_sink(sink);
}
catch(std::exception ex)
{
return false;
}
return true;
}
bool DragonFiesta::Log::SetupLogLevel(LogTag tag,int Level)
{
if(Level > 4)
{
LogMessage(ERROR,"Invalid LogLevel Found %d %d",tag,Level);
return false;
}
LogLevels[tag] = Level;
return true;
}
void DragonFiesta::Log::LogMessage(severity_level Level,const char* format, ... )
{
boost::log::sources::severity_logger< severity_level > slg;
std::stringstream outstream;
char buf[32768];
va_list arglist;
va_start( arglist,format);
vsnprintf(buf, 32768, format, arglist);
outstream << buf;
va_end( arglist );
BOOST_LOG_SEV(slg, Level) << outstream.str() ;
}
void DragonFiesta::Log::LogMessage(severity_level Level,LogTag Tag,const char* format, ... )
{
boost::log::sources::severity_logger< severity_level > slg;
std::stringstream outstream;
char buf[32768];
va_list arglist;
va_start( arglist,format);
vsnprintf(buf, 32768, format, arglist);
outstream << buf;
va_end( arglist );
BOOST_LOG_SCOPED_THREAD_TAG("Tag", Tagstrings[Tag]);
BOOST_LOG_SEV(slg, Level) << outstream.str();
}
void DragonFiesta::Log::LogConsole(boost::log::record_v iew const& rec, boost::log::formatting_ostream& strm)
{
std::stringstream outstream;
std::stringstream ColorLevel;
outstream << "[" << LogDateString() << "]";
if(rec[tag_attr] != "")
{
outstream << "[" << rec[tag_attr] << "]";
}
outstream << "[" << rec[severity] << "] : " << *rec[boost::log::expressions::smessage];
//MSG END
ColorLevel << rec[severity];
int ConsolColor = LogLevelColors[ColorLevel.str()];
SetConsoleColor(ConsolColor);
std::cout << outstream.str() << std::endl;
}
bool DragonFiesta::Log::Log_Filter(boost::log::value_re f< severity_level, tag::severity > const& level,boost::log::value_ref< std::string, tag::tag_attr > const& tag)
{
return ( (level >= LogLevels[0] && tag == Tagstrings[0])
||(level >= LogLevels[1] && tag == Tagstrings[1])
||(level >= LogLevels[2] && tag == Tagstrings[2])
||(level >= LogLevels[3] && !tag));
}
void DragonFiesta::Log::SetConsoleColor(int textcolor,int backColor)
{
#ifdef _WIN32
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), textcolor + ( backcolor << 4 ) );
#else
printf("\033[%02x;%02xm", (textcolor & 0xFF00)>>8, textcolor & 0xFF);
#endif
}
std::string DragonFiesta::Log::LogDateString()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return buf;
}
Mein Fehler code

[/QUOTE][/SPOILER]
Danke um voraus wenn jmd mit verbessern kann oder mirn tipp gibt wie ich den kram korrect hinbekommen






