Procházet zdrojové kódy

Move code around and fix build errors.

Sam Jaffe před 6 roky
rodič
revize
f11950c353

+ 4 - 0
logger.xcodeproj/project.pbxproj

@@ -32,6 +32,7 @@
 		CD88E95F2252D3EF00927F40 /* c_logger.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD88E95D2252D3EF00927F40 /* c_logger.cxx */; };
 		CD88E9632252D67A00927F40 /* common.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD88E9612252D67A00927F40 /* common.cxx */; };
 		CDA494DE2256D5F40041620C /* pattern_layout_date.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDA494DD2256D5F40041620C /* pattern_layout_date.cxx */; };
+		CDC0E0512269378E001EDAB7 /* message.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDC0E0502269378E001EDAB7 /* message.cxx */; };
 		CDEA62D5225A3B0B00A6FAE0 /* json_layout.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDEA62D4225A3B0B00A6FAE0 /* json_layout.cxx */; };
 /* End PBXBuildFile section */
 
@@ -107,6 +108,7 @@
 		CDA494DD2256D5F40041620C /* pattern_layout_date.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = pattern_layout_date.cxx; sourceTree = "<group>"; };
 		CDC0E0472267EA30001EDAB7 /* logger_impl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = logger_impl.h; sourceTree = "<group>"; };
 		CDC0E04C2267F8A9001EDAB7 /* pattern_layout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pattern_layout.h; sourceTree = "<group>"; };
+		CDC0E0502269378E001EDAB7 /* message.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = message.cxx; sourceTree = "<group>"; };
 		CDEA62D4225A3B0B00A6FAE0 /* json_layout.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = json_layout.cxx; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -179,6 +181,7 @@
 				CDC0E0472267EA30001EDAB7 /* logger_impl.h */,
 				CD1CDEAE22556B7E00E5B6B2 /* logger_impl.cxx */,
 				CD88E9552252BDFC00927F40 /* log_manager.cxx */,
+				CDC0E0502269378E001EDAB7 /* message.cxx */,
 				CD88E9642252D6C700927F40 /* common.h */,
 				CD88E9612252D67A00927F40 /* common.cxx */,
 			);
@@ -381,6 +384,7 @@
 				CD1CDEB52256C94000E5B6B2 /* pattern_layout.cxx in Sources */,
 				CD88E9632252D67A00927F40 /* common.cxx in Sources */,
 				CD1CDEB122557FB600E5B6B2 /* default_layout.cxx in Sources */,
+				CDC0E0512269378E001EDAB7 /* message.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 0
src/common.h

@@ -7,6 +7,7 @@
 
 #pragma once
 
+#include <string>
 #include <sys/time.h>
 
 namespace logging {

+ 0 - 23
src/loggers/pattern_layout_format.cxx

@@ -145,27 +145,4 @@ namespace logging {
     process(pkt, ss);
     return ss.str();
   }
-
-  void format_msg(std::ostream & os, std::string const & interp, size_t pos,
-                  std::vector<detail::object> const & objs, size_t idx) {
-    size_t next = interp.find("{}", pos);
-    os << interp.substr(pos, next);
-    if (next == std::string::npos) {
-      return; // throw?
-    } else if (!strncmp(interp.c_str() + next - 1, "{{}}", 4)) {
-      format_msg(os, interp, next+2, objs, idx);
-    } else {
-      format_msg(os << objs[idx], interp, next+2, objs, idx+1);
-    }
-  }
-  
-  std::string message::str() const {
-    std::stringstream ss;
-    format_msg(ss, format_code, 0, objects, 0);
-    return ss.str();
-  }
-  
-  Json::Value message::json() const {
-    return objects[0].json();
-  }
 }

+ 35 - 0
src/message.cxx

@@ -0,0 +1,35 @@
+//
+//  message.cxx
+//  logging
+//
+//  Created by Sam Jaffe on 4/18/19.
+//
+
+#include "logger/message.h"
+
+#include <sstream>
+
+namespace logging {
+  void format_msg(std::ostream & os, std::string const & interp, size_t pos,
+                  std::vector<detail::object> const & objs, size_t idx) {
+    size_t next = interp.find("{}", pos);
+    os << interp.substr(pos, next);
+    if (next == std::string::npos) {
+      return; // throw?
+    } else if (!strncmp(interp.c_str() + next - 1, "{{}}", 4)) {
+      format_msg(os, interp, next+2, objs, idx);
+    } else {
+      format_msg(os << objs[idx], interp, next+2, objs, idx+1);
+    }
+  }
+  
+  std::string message::str() const {
+    std::stringstream ss;
+    format_msg(ss, format_code, 0, objects, 0);
+    return ss.str();
+  }
+  
+  Json::Value message::json() const {
+    return objects[0].json();
+  }
+}