server : change message format of server_log()

This commit is contained in:
Georgi Gerganov 2024-02-24 15:03:08 +02:00
parent 65e65fd6c0
commit f23aa90994
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
2 changed files with 27 additions and 19 deletions

View file

@ -2593,13 +2593,15 @@ static json format_partial_response(
static json format_tokenizer_response(const std::vector<llama_token> &tokens) static json format_tokenizer_response(const std::vector<llama_token> &tokens)
{ {
return json { return json {
{"tokens", tokens}}; {"tokens", tokens}
};
} }
static json format_detokenized_response(std::string content) static json format_detokenized_response(std::string content)
{ {
return json { return json {
{"content", content}}; {"content", content}
};
} }

View file

@ -32,8 +32,8 @@ extern bool server_verbose;
} while (0) } while (0)
#endif #endif
#define LOG_ERROR( MSG, ...) server_log("ERROR", __func__, __LINE__, MSG, __VA_ARGS__) #define LOG_ERROR( MSG, ...) server_log("ERR", __func__, __LINE__, MSG, __VA_ARGS__)
#define LOG_WARNING(MSG, ...) server_log("WARNING", __func__, __LINE__, MSG, __VA_ARGS__) #define LOG_WARNING(MSG, ...) server_log("WARN", __func__, __LINE__, MSG, __VA_ARGS__)
#define LOG_INFO( MSG, ...) server_log("INFO", __func__, __LINE__, MSG, __VA_ARGS__) #define LOG_INFO( MSG, ...) server_log("INFO", __func__, __LINE__, MSG, __VA_ARGS__)
// //
@ -136,19 +136,25 @@ struct completion_token_output
static inline void server_log(const char *level, const char *function, int line, static inline void server_log(const char *level, const char *function, int line,
const char *message, const nlohmann::ordered_json &extra) const char *message, const nlohmann::ordered_json &extra)
{ {
nlohmann::ordered_json log char buf[1024];
{ snprintf(buf, 1024, "%24s %4s: %-80s", function, level, message);
{"timestamp", time(nullptr)},
{"level", level},
{"function", function},
{"line", line},
{"message", message},
};
auto thread_id = std::this_thread::get_id(); nlohmann::ordered_json log;
{
std::stringstream ss_thread_id; std::stringstream ss_thread_id;
ss_thread_id << thread_id; ss_thread_id << std::this_thread::get_id();
log.push_back({"thread_id", ss_thread_id.str()}); log.push_back({"tid", ss_thread_id.str()});
}
log.merge_patch(
{
//{"timestamp", time(nullptr)},
//{"level", level},
//{"function", function},
//{"line", line},
{"msg", buf},
});
if (!extra.empty()) if (!extra.empty())
{ {