ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
2.2 KiB

  1. #ifndef CPPCMS_LOGGER_H
  2. #define CPPCMS_LOGGER_H
  3. #include "defs.h"
  4. #include <iosfwd>
  5. #include <memory>
  6. #include "copy_ptr.h"
  7. #include "hold_ptr.h"
  8. #include "noncopyable.h"
  9. namespace cppcms {
  10. class CPPCMS_API logger : public util::noncopyable {
  11. public:
  12. typedef enum {
  13. fatal = 10,
  14. critical= 20,
  15. error = 30,
  16. warning = 40,
  17. message = 50,
  18. info = 60,
  19. debug = 70,
  20. all = 100
  21. } level_type;
  22. class CPPCMS_API ostream_proxy {
  23. public:
  24. ostream_proxy();
  25. ostream_proxy(level_type level,char const *module,char const *file,int line,logger *log);
  26. ~ostream_proxy();
  27. ostream_proxy(ostream_proxy &other);
  28. ostream_proxy &operator=(ostream_proxy &other);
  29. std::ostream &out();
  30. private:
  31. level_type level_;
  32. int line_;
  33. char const *file_;
  34. char const *module_;
  35. logger *log_;
  36. struct data;
  37. util::copy_ptr<data> d;
  38. std::auto_ptr<std::ostringstream> output_;
  39. };
  40. void write_to_log(level_type l,char const *module,char const *file,int line,std::string const &message);
  41. bool level(level_type l,char const *module);
  42. ostream_proxy proxy(level_type l,char const *module,char const *file,int line);
  43. void default_level(level_type l);
  44. level_type default_level();
  45. void module_level(char const *module,level_type l);
  46. level_type module_level(char const *module);
  47. void reset_module_level(char const *module);
  48. typedef enum {
  49. overwrite = 0,
  50. append = 1
  51. } open_mode_type;
  52. void log_to_file(std::string const &file_name,open_mode_type mode = append);
  53. void log_to_stdout();
  54. void log_to_stderr();
  55. static logger &instance();
  56. private:
  57. static void init(std::auto_ptr<logger> &logger_ref);
  58. struct data;
  59. util::hold_ptr<data> d;
  60. };
  61. #define CPPCMS_LOG(_l,_m) \
  62. ::cppcms::logger::instance().level(::cppcms::logger::_l,_m) \
  63. && ::cppcms::logger::instance().proxy(::cppcms::logger::_l,_m,__FILE__,__LINE__).out()
  64. #define CPPCMS_FATAL(_m) CPPCMS_LOG(fatal,_m)
  65. #define CPPCMS_CRITICAL(_m) CPPCMS_LOG(critical,_m)
  66. #define CPPCMS_ERROR(_m) CPPCMS_LOG(error,_m)
  67. #define CPPCMS_WARNING(_m) CPPCMS_LOG(warning,_m)
  68. #define CPPCMS_MESSAGE(_m) CPPCMS_LOG(message,_m)
  69. #define CPPCMS_INFO(_m) CPPCMS_LOG(info,_m)
  70. #define CPPCMS_DEBUG(_m) CPPCMS_LOG(debug,_m)
  71. } // CppCMS
  72. #endif