00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_LOG_HH
00021 #define PALUDIS_GUARD_PALUDIS_LOG_HH 1
00022
00023 #include <iosfwd>
00024 #include <string>
00025 #include <paludis/util/stringify.hh>
00026 #include <paludis/util/instantiation_policy.hh>
00027 #include <paludis/util/private_implementation_pattern.hh>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 namespace paludis
00040 {
00041 #include <paludis/util/log-se.hh>
00042
00043 class LogMessageHandler;
00044
00045
00046
00047
00048
00049
00050 class PALUDIS_VISIBLE Log :
00051 public InstantiationPolicy<Log, instantiation_method::SingletonTag>,
00052 private PrivateImplementationPattern<Log>
00053 {
00054 friend class InstantiationPolicy<Log, instantiation_method::SingletonTag>;
00055 friend class LogMessageHandler;
00056
00057 private:
00058 Log();
00059
00060 void _message(const std::string & id, const LogLevel, const LogContext, const std::string &);
00061
00062 public:
00063
00064
00065
00066 ~Log();
00067
00068
00069
00070
00071 void set_log_level(const LogLevel);
00072
00073
00074
00075
00076 LogLevel log_level() const
00077 PALUDIS_ATTRIBUTE((warn_unused_result));
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 LogMessageHandler message(const std::string & id,
00088 const LogLevel, const LogContext) PALUDIS_ATTRIBUTE((warn_unused_result));
00089
00090
00091
00092
00093 void set_log_stream(std::ostream * const);
00094
00095
00096
00097
00098 void set_program_name(const std::string &);
00099
00100
00101
00102
00103 void complete_pending() const;
00104 };
00105
00106
00107
00108
00109
00110
00111
00112 class PALUDIS_VISIBLE LogMessageHandler
00113 {
00114 friend LogMessageHandler Log::message(const std::string &, const LogLevel, const LogContext);
00115
00116 private:
00117 Log * _log;
00118 std::string _id;
00119 std::string _message;
00120 LogLevel _log_level;
00121 LogContext _log_context;
00122
00123 LogMessageHandler(const LogMessageHandler &);
00124 LogMessageHandler(Log * const, const std::string &, const LogLevel, const LogContext);
00125 void operator= (const LogMessageHandler &);
00126
00127 void _append(const std::string & s);
00128
00129 public:
00130
00131
00132
00133 ~LogMessageHandler();
00134
00135
00136
00137
00138
00139
00140 template <typename T_>
00141 LogMessageHandler &
00142 operator<< (const T_ & t)
00143 {
00144 _append(stringify(t));
00145 return *this;
00146 }
00147 };
00148 }
00149
00150 #endif