   C++ Logger Tutorial
  Hello to all, i written a simple staff personnel system that able to login and serialize data to file. Therefore, i need to logging each login session success and failure and whenever a add, delete or edit the file, a logging feature to the file. Besides that, program logging also function i looking for. Please point me to simple tutorial. I don't want any log4J variant library. I need to write a simple one from scratch. Thanks.[Edited by - Peter_APIIT on June 27, 2009 9:03:50 AM]
  Unless you really need to make it yourself, I would recommend finding an existing package, for example Apache log4cxx. It will save you a lot of time and debugging.;Quote:Original post by Peter_APIITPlease point me to simple tutorial. I don't want any log4J variant library. I need to write a simple one from scratch. If you want a simple, malleable logging library, you could try this.   ;  The reason i code this from scratch is i am a student and i would like to enhance my programming skills and learn the logging techniques. I try search in google but nothing found. Thanks.   ;  Maybe gamedev.net log tutorial ?. Simple STL Logging System;  Personally, I use this as the base for my log classes:enum LogLevel{  LL_DEBUG,  LL_VERBOSE,  LL_NORMAL,  LL_ERROR,  LL_FATALERROR};class Log  : public boost::noncopyable{public:  Log(const std::string& name, LogLevel ll)    : m_name(name), m_level(ll)  {  }  virtual ~Log( ) { }  const std::string& getName( ) const { return m_name; }  LogLevel getLevel( ) const { return m_level; }  void setLevel(LogLevel ll) { m_level = ll; }  void printDebug(const std::string& str)  {#ifndef LOG_DISABLE_DEBUG    printMsg(LL_DEBUG, str);#endif // LOG_DISABLE_DEBUG  }  void printVerbose(const std::string& str)  {#ifndef LOG_DISABLE_VERBOSE    printMsg(LL_VERBOSE, str);#endif // LOG_DISABLE_VERBOSE  }  void printNormal(const std::string& str)  {    printMsg(LL_NORMAL, str);  }  void printError(const std::string& str)  {    printMsg(LL_ERROR, str);  }  void printFatalError(const std::string& str)  {    printMsg(LL_FATALERROR, str);  }    void printMsg(LogLevel ll, const std::string& str)  {    if (ll >= m_level)    { print(str);    }  }  virtual void print(const std::string& str) = 0;private:  std::string m_name;  LogLevel m_level;};typedef boost::shared_ptr<Log> LogPtr;Anything then that is considered a "log" inherits from that.  Files, in-game chat, combat logs, etc.  There's also a class which holds other logs and and will print to all of them.  The result is that anywhere you want to log something, you can easily send it to any destination you desire, eg:class Foo{public:  Foo(LogPtr log = LogPtr( ))    : m_log(log)  {  }    void bar( )  {    if (m_log) m_log->printDebug("Foo::bar"); }  private:  LogPtr m_log;};int main( ){    Foo a; // no log  a.bar( );  LogFilePtr file(new LogFile(...));    Foo b(file); // log to file  b.bar( );    ChatLogPtr chat(new ChatLog(...));  CombatLogPtr cl(new CombatLog(...));  MultiLogPtr ml(new MultiLogPtr(...));    ml->addLog(file);  ml->addLog(chat);  ml->addLog(cl);    Foo c(ml); // log to file, chat and combat  c.bar( );};  Thanks. Look forward for other reply too.   