| 973 | } |
| 974 | |
| 975 | void PrintLog(std::ostream& os, int severity, const char* file, int line, |
| 976 | const char* func, const butil::StringPiece& content) { |
| 977 | if (!FLAGS_log_as_json) { |
| 978 | PrintLogPrefix(os, severity, file, line, func, GetTimestamp()); |
| 979 | OutputLog(os, content); |
| 980 | } else { |
| 981 | os << '{'; |
| 982 | PrintLogPrefixAsJSON(os, severity, file, func, line, GetTimestamp()); |
| 983 | bool pair_quote = false; |
| 984 | if (content.empty() || content[0] != '"') { |
| 985 | // not a json, add a 'M' field |
| 986 | os << ",\"M\":\""; |
| 987 | pair_quote = true; |
| 988 | } else { |
| 989 | os << ','; |
| 990 | } |
| 991 | OutputLog(os, content); |
| 992 | if (pair_quote) { |
| 993 | os << '"'; |
| 994 | } else if (!content.empty() && content[content.size() -1 ] != '"') { |
| 995 | // Controller may write `"M":"...` which misses the last quote |
| 996 | os << '"'; |
| 997 | } |
| 998 | os << '}'; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | void PrintLog(std::ostream& os, |
| 1003 | int severity, const char* file, int line, |
no test coverage detected