Utils/Logger: Complete unit testing
[senf.git] / Utils / Logger / Parameters.ih
index d323241..5370f97 100644 (file)
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/fold.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/utility.hpp>
+#include <boost/type_traits/is_convertible.hpp>
 #include "../mpl.hh"
 #include "Config.hh"
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
-#ifndef _senf_LOG_STREAM
-#   define _senf_LOG_STREAM std::cerr
-#endif
-
 namespace senf {
 namespace log {
     
@@ -70,7 +69,7 @@ namespace detail {
     senf::mpl::rv<2> Parameters_select_(AreaBase *);
     template <class Base, class Param>
     struct Parameters_<Base,Param,2> : public Base
-    { typedef Param area; };
+    { typedef Param area; typedef Param area_base; };
 
     senf::mpl::rv<3> Parameters_select_(LevelBase *);
     template <class Base, class Param>
@@ -99,7 +98,7 @@ namespace detail {
         typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
     template <class Base, class Param>
     struct Parameters_<Base,Param,6> : public Base
-    { typedef typename Param::SENFLogArea area; };
+    { typedef typename Param::SENFLogArea area; typedef Param area_base; };
 
 #endif
 
@@ -107,13 +106,19 @@ namespace detail {
     template <class Base>
     struct Parameters : public Base
     {
-        static bool const compile_enabled = senf::log::Enabled<
+        typedef typename boost::mpl::if_c< Base::level::value == NONE::value, 
+                                           typename Base::stream::defaultLevel, 
+                                           typename Base::level >::type level;
+
+        static bool const compileEnabled = senf::log::Enabled<
             typename Base::stream, 
-            typename Base::area, 
-            typename Base::level>::value;
+            typename Base::area_base, 
+            level>::value;
 
-        static bool enabled() { return compile_enabled; }
-        static std::ostream & log_stream() { return _senf_LOG_STREAM; }
+        static bool enabled() { 
+            return compileEnabled
+                && Base::area::instance().limit(Base::stream::instance()) <= level::value;
+        }
     };
 
     /// Internal: Empty base class