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.
 
 
 
 
 
 

108 lines
3.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef CPPCMS_LOGGER_H
  20. #define CPPCMS_LOGGER_H
  21. #include "defs.h"
  22. #include <iosfwd>
  23. #include <memory>
  24. #include <booster/copy_ptr.h>
  25. #include <booster/hold_ptr.h>
  26. #include <booster/noncopyable.h>
  27. namespace cppcms {
  28. class CPPCMS_API logger : public booster::noncopyable {
  29. public:
  30. typedef enum {
  31. fatal = 10,
  32. critical= 20,
  33. error = 30,
  34. warning = 40,
  35. message = 50,
  36. info = 60,
  37. debug = 70,
  38. all = 100
  39. } level_type;
  40. class CPPCMS_API ostream_proxy {
  41. public:
  42. ostream_proxy();
  43. ostream_proxy(level_type level,char const *module,char const *file,int line,logger *log);
  44. ~ostream_proxy();
  45. ostream_proxy(ostream_proxy &other);
  46. ostream_proxy &operator=(ostream_proxy &other);
  47. std::ostream &out();
  48. private:
  49. level_type level_;
  50. int line_;
  51. char const *file_;
  52. char const *module_;
  53. logger *log_;
  54. struct data;
  55. booster::copy_ptr<data> d;
  56. std::auto_ptr<std::ostringstream> output_;
  57. };
  58. void write_to_log(level_type l,char const *module,char const *file,int line,std::string const &message);
  59. bool level(level_type l,char const *module);
  60. ostream_proxy proxy(level_type l,char const *module,char const *file,int line);
  61. void default_level(level_type l);
  62. level_type default_level();
  63. void module_level(char const *module,level_type l);
  64. level_type module_level(char const *module);
  65. void reset_module_level(char const *module);
  66. typedef enum {
  67. overwrite = 0,
  68. append = 1
  69. } open_mode_type;
  70. void log_to_file(std::string const &file_name,open_mode_type mode = append);
  71. void log_to_stdout();
  72. void log_to_stderr();
  73. static logger &instance();
  74. private:
  75. static void init(std::auto_ptr<logger> &logger_ref);
  76. struct data;
  77. booster::hold_ptr<data> d;
  78. };
  79. #define CPPCMS_LOG(_l,_m) \
  80. ::cppcms::logger::instance().level(::cppcms::logger::_l,_m) \
  81. && ::cppcms::logger::instance().proxy(::cppcms::logger::_l,_m,__FILE__,__LINE__).out()
  82. #define CPPCMS_FATAL(_m) CPPCMS_LOG(fatal,_m)
  83. #define CPPCMS_CRITICAL(_m) CPPCMS_LOG(critical,_m)
  84. #define CPPCMS_ERROR(_m) CPPCMS_LOG(error,_m)
  85. #define CPPCMS_WARNING(_m) CPPCMS_LOG(warning,_m)
  86. #define CPPCMS_MESSAGE(_m) CPPCMS_LOG(message,_m)
  87. #define CPPCMS_INFO(_m) CPPCMS_LOG(info,_m)
  88. #define CPPCMS_DEBUG(_m) CPPCMS_LOG(debug,_m)
  89. } // CppCMS
  90. #endif