Log.h 863 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright: All Rights Reserved
  2. // Author: egametang@gmail.com (tanghai)
  3. #ifndef BASE_LOG_H
  4. #define BASE_LOG_H
  5. #include <string>
  6. #include <boost/scoped_ptr.hpp>
  7. #include <boost/noncopyable.hpp>
  8. #include <boost/shared_ptr.hpp>
  9. #include <boost/log/trivial.hpp>
  10. #include <boost/log/sources/severity_logger.hpp>
  11. namespace Egametang {
  12. #define LOG(level) BOOST_LOG_SEV(Log::GetSLog(), level) << "[" << FileName(__FILE__) << ":" << __LINE__ << "] "
  13. std::string FileName(std::string s);
  14. enum SeverityLevel
  15. {
  16. INFO = 0,
  17. WARN = 1,
  18. ERR = 2,
  19. FATAL = 3,
  20. };
  21. class Log: public boost::noncopyable
  22. {
  23. private:
  24. static boost::scoped_ptr< boost::log::sources::severity_logger<SeverityLevel> > slog;
  25. public:
  26. static void Init(std::string fileName);
  27. static boost::log::sources::severity_logger<SeverityLevel>& GetSLog();
  28. };
  29. }
  30. #endif // BASE_LOG_H