4 #include <log4cpp/Appender.hh>
5 #include <log4cpp/Category.hh>
6 #include <log4cpp/FileAppender.hh>
7 #include <log4cpp/OstreamAppender.hh>
8 #include <log4cpp/PatternLayout.hh>
9 #include <log4cpp/Priority.hh>
10 #include <log4cpp/PropertyConfigurator.hh>
13 #include <sys/types.h>
21 const std::string initFileName =
"phlog.conf";
22 const char* env_file = std::getenv(
"PHLOGCONF");
25 log4cpp::PropertyConfigurator::configure(initFileName);
29 log4cpp::PropertyConfigurator::configure(std::string(
_get_homedir()) +
"/" + initFileName);
33 log4cpp::PropertyConfigurator::configure(env_file);
37 log4cpp::PatternLayout* layout1 =
new log4cpp::PatternLayout();
38 layout1->setConversionPattern(
"%d [%p] %c: %m%n");
39 log4cpp::Appender* appender1 =
new log4cpp::OstreamAppender(
"console", &std::cout);
40 appender1->setLayout(layout1);
41 log4cpp::Category& root = log4cpp::Category::getRoot();
43 root.addAppender(appender1);
49 log4cpp::Category::shutdown();
52 static log4cpp::Category&
get(
const std::string& category =
"")
54 static bool phlog_is_initialized =
false;
55 if (!phlog_is_initialized)
58 phlog_is_initialized =
true;
60 return log4cpp::Category::getInstance(category);
66 struct passwd* pw = getpwuid(getuid());
73 return (stat(filename.c_str(), &
buffer) == 0);
79 #define LOG_DEBUG_IF(category, cond) \
80 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::DEBUG) && (cond)) \
81 PHLog::get(category) << log4cpp::Priority::DEBUG
83 #define LOG_INFO_IF(category, cond) \
84 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::INFO) && (cond)) \
85 PHLog::get(category) << log4cpp::Priority::INFO
87 #define LOG_NOTICE_IF(category, cond) \
88 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::NOTICE) && (cond)) \
89 PHLog::get(category) << log4cpp::Priority::NOTICE
91 #define LOG_WARN_IF(category, cond) \
92 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::WARN) && (cond)) \
93 PHLog::get(category) << log4cpp::Priority::WARN
95 #define LOG_ERROR_IF(category, cond) \
96 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::ERROR) && (cond)) \
97 PHLog::get(category) << log4cpp::Priority::ERROR
99 #define LOG_CRIT_IF(category, cond) \
100 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::CRIT) && (cond)) \
101 PHLog::get(category) << log4cpp::Priority::CRIT
103 #define LOG_ALERT_IF(category, cond) \
104 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::ALERT) && (cond)) \
105 PHLog::get(category) << log4cpp::Priority::ALERT
107 #define LOG_FATAL_IF(category, cond) \
108 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::FATAL) && (cond)) \
109 PHLog::get(category) << log4cpp::Priority::FATAL
113 #define LOG_DEBUG(category) \
114 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::DEBUG)) \
115 PHLog::get(category) << log4cpp::Priority::DEBUG
117 #define LOG_INFO(category) \
118 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::INFO)) \
119 PHLog::get(category) << log4cpp::Priority::INFO
121 #define LOG_NOTICE(category) \
122 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::NOTICE)) \
123 PHLog::get(category) << log4cpp::Priority::NOTICE
125 #define LOG_WARN(category) \
126 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::WARN)) \
127 PHLog::get(category) << log4cpp::Priority::WARN
129 #define LOG_ERROR(category) \
130 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::ERROR)) \
131 PHLog::get(category) << log4cpp::Priority::ERROR
133 #define LOG_CRIT(category) \
134 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::CRIT)) \
135 PHLog::get(category) << log4cpp::Priority::CRIT
137 #define LOG_ALERT(category) \
138 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::ALERT)) \
139 PHLog::get(category) << log4cpp::Priority::ALERT
141 #define LOG_FATAL(category) \
142 if (PHLog::get(category).isPriorityEnabled(log4cpp::Priority::FATAL)) \
143 PHLog::get(category) << log4cpp::Priority::FATAL
145 #endif // PHOOL_PHLOG_H