Quellcode durchsuchen

Export properties

Sam Jaffe vor 6 Jahren
Ursprung
Commit
9e2736e942
3 geänderte Dateien mit 50 neuen und 53 gelöschten Zeilen
  1. 10 0
      include/logger/properties.h
  2. 9 17
      src/loggers/properties.cxx
  3. 31 36
      test/test_properties.cxx

+ 10 - 0
include/logger/properties.h

@@ -39,6 +39,16 @@ namespace logging {
     variant<object_t, array_t, std::string, int, bool> data;
   };
   
+  namespace property {
+    inline properties _obj(object_t const& m) { return {m}; }
+    inline properties _arr(array_t const& l) { return {l}; }
+    inline properties _v(std::string const & t) { return {t}; }
+    // [char const *] will cast to [int] over [std::string const &]
+    inline properties _v(char const * t) { return {std::string(t)}; }
+    inline properties _v(int t) { return {t}; }
+    inline properties _v(bool t) { return {t}; }
+  }
+  
   extern properties const DEFAULT_APPENDER_SCHEMA;
   extern properties const DEFAULT_LOGGER_SCHEMA;
 }

+ 9 - 17
src/loggers/properties.cxx

@@ -18,16 +18,8 @@
  "PatternLayout"
  }
  */
+using namespace logging::property;
 namespace logging {
-  namespace {
-    properties _property(object_t const& m) {
-      properties pr{m};
-      return pr;
-    }
-//    properties _list(array_t const& l) { return {l}; }
-    properties _v(std::string const & t) { return {t}; }
-  }
-  
   /*
    * %d{%h:%M:%s.%_ms} [%t] %-5.5p %.36c - %m%n
    *
@@ -43,22 +35,22 @@ namespace logging {
   extern properties const DEFAULT_APPENDER_SCHEMA;
   extern properties const DEFAULT_LOGGER_SCHEMA;
   
-  properties const DEFAULT_APPENDER_SCHEMA{_property({
-    {"appenders", _property({
-      {"Console", _property({
+  properties const DEFAULT_APPENDER_SCHEMA{_obj({
+    {"appenders", _obj({
+      {"Console", _obj({
         {"target", _v("SYSTEM_OUT")},
-        {"PatternLayout", _property({
+        {"PatternLayout", _obj({
           {"pattern", _v("%d{%h:%M:%s.%_ms} [%t] %-5.5p %.36c - %m%n")}
         })}
       })}
     })}
   })};
     
-  properties const DEFAULT_LOGGER_SCHEMA{_property({
-    {"loggers", _property({
-      {"root", _property({
+  properties const DEFAULT_LOGGER_SCHEMA{_obj({
+    {"loggers", _obj({
+      {"root", _obj({
         {"level", _v("Error")},
-        {"appenders", _property({
+        {"appenders", _obj({
           {"ref", _v("Console")}
         })}
       })}

+ 31 - 36
test/test_properties.cxx

@@ -8,28 +8,23 @@
 #include "logger/properties.h"
 
 using logging::properties;
-
-namespace {
-  properties _property(logging::object_t const& m) { return {m}; }
-  properties _list(logging::array_t const& l) { return {l}; }
-  properties _v(std::string const & t) { return {t}; }
-}
+using namespace logging::property;
 
 extern properties const APPENDER_LEVEL_PROPERTY_SCHEMA;
 extern properties const LOGGER_LEVEL_PROPERTY_SCHEMA;
 extern properties const MIN_PROPERTY_SCHEMA;
 extern properties const MULTIPLEX_PROPERTY_SCHEMA;
 
-properties const MIN_PROPERTY_SCHEMA{_property({
-  {"configuration", _property({
-    {"appenders", _property({
-      {"Mock", _property({
+properties const MIN_PROPERTY_SCHEMA{_obj({
+  {"configuration", _obj({
+    {"appenders", _obj({
+      {"Mock", _obj({
         {"MockLayout", _v("")}
       })}
     })},
-    {"loggers", _property({
-      {"root", _property({
-        {"appenders", _property({
+    {"loggers", _obj({
+      {"root", _obj({
+        {"appenders", _obj({
           {"ref", _v("Mock")}
         })}
       })}
@@ -37,17 +32,17 @@ properties const MIN_PROPERTY_SCHEMA{_property({
   })}
 })};
 
-properties const APPENDER_LEVEL_PROPERTY_SCHEMA{_property({
-  {"configuration", _property({
-    {"appenders", _property({
-      {"Mock", _property({
+properties const APPENDER_LEVEL_PROPERTY_SCHEMA{_obj({
+  {"configuration", _obj({
+    {"appenders", _obj({
+      {"Mock", _obj({
         {"level", _v("Warning")},
         {"MockLayout", _v("")}
       })}
     })},
-    {"loggers", _property({
-      {"root", _property({
-        {"appenders", _property({
+    {"loggers", _obj({
+      {"root", _obj({
+        {"appenders", _obj({
           {"ref", _v("Mock")}
         })}
       })}
@@ -55,18 +50,18 @@ properties const APPENDER_LEVEL_PROPERTY_SCHEMA{_property({
   })}
 })};
 
-properties const LOGGER_LEVEL_PROPERTY_SCHEMA{_property({
-  {"configuration", _property({
-    {"appenders", _property({
-      {"Mock", _property({
+properties const LOGGER_LEVEL_PROPERTY_SCHEMA{_obj({
+  {"configuration", _obj({
+    {"appenders", _obj({
+      {"Mock", _obj({
         {"level", _v("Warning")},
         {"MockLayout", _v("")}
       })}
     })},
-    {"loggers", _property({
-      {"root", _property({
+    {"loggers", _obj({
+      {"root", _obj({
         {"level", _v("Error")},
-        {"appenders", _property({
+        {"appenders", _obj({
           {"ref", _v("Mock")}
         })}
       })}
@@ -74,18 +69,18 @@ properties const LOGGER_LEVEL_PROPERTY_SCHEMA{_property({
   })}
 })};
 
-properties const MULTIPLEX_PROPERTY_SCHEMA{_property({
-  {"configuration", _property({
-    {"appenders", _property({
-      {"Mock", _property({
+properties const MULTIPLEX_PROPERTY_SCHEMA{_obj({
+  {"configuration", _obj({
+    {"appenders", _obj({
+      {"Mock", _obj({
         {"MockLayout", _v("")}
       })}
     })},
-    {"loggers", _property({
-      {"root", _property({
-        {"appenders", _list({
-          _property({{"ref", _v("Mock")}}),
-          _property({{"ref", _v("Mock")}})
+    {"loggers", _obj({
+      {"root", _obj({
+        {"appenders", _arr({
+          _obj({{"ref", _v("Mock")}}),
+          _obj({{"ref", _v("Mock")}})
         })}
       })}
     })}