77#include < vector>
88
99// #include "preprocessing.hpp"
10- #include " b64.cpp"
1110#include " flux.hpp"
12- #include " json.hpp"
1311#include " stable-diffusion.h"
1412
1513#define STB_IMAGE_IMPLEMENTATION
2422#define STB_IMAGE_RESIZE_STATIC
2523#include " stb_image_resize.h"
2624
25+ #include " b64.cpp"
2726#include " httplib.h"
28- #include " util.h "
27+ #include " json.hpp "
2928
3029const char * rng_type_to_str[] = {
3130 " std_default" ,
@@ -566,6 +565,22 @@ void sd_log_cb(enum sd_log_level_t level, const char* log, void* data) {
566565 fflush (out_stream);
567566}
568567
568+ void * server_log_params = NULL ;
569+
570+ // enable logging in the server
571+ #define LOG_BUFFER_SIZE 1024
572+ const auto sd_log (enum sd_log_level_t level, const char * format, ...) {
573+ va_list args;
574+ va_start (args, format);
575+
576+ char log[LOG_BUFFER_SIZE];
577+ vsnprintf (log, 1024 , format, args);
578+ strncat (log, " \n " , LOG_BUFFER_SIZE - strlen (log));
579+
580+ sd_log_cb (level, log, server_log_params);
581+ va_end (args);
582+ }
583+
569584static void log_server_request (const httplib::Request& req, const httplib::Response& res) {
570585 printf (" request: %s %s (%s)\n " , req.method .c_str (), req.path .c_str (), req.body .c_str ());
571586}
@@ -614,7 +629,8 @@ void parseJsonPrompt(std::string json_str, SDParams* params) {
614629 try {
615630 std::string sample_method = payload[" sample_method" ];
616631 // TODO map to enum value
617- LOG_WARN (" sample_method is not supported yet\n " );
632+ // LOG_WARN("sample_method is not supported yet\n");
633+ sd_log (sd_log_level_t ::SD_LOG_WARN, " sample_method is not supported yet\n " , params);
618634 } catch (...) {
619635 }
620636 try {
@@ -636,7 +652,8 @@ void parseJsonPrompt(std::string json_str, SDParams* params) {
636652 try {
637653 std::string control_cond = payload[" control_cond" ];
638654 // TODO map to enum value
639- LOG_WARN (" control_cond is not supported yet\n " );
655+ // LOG_WARN("control_cond is not supported yet\n");
656+ sd_log (sd_log_level_t ::SD_LOG_WARN, " control_cond is not supported yet\n " , params);
640657 } catch (...) {
641658 }
642659 try {
@@ -666,6 +683,8 @@ int main(int argc, const char* argv[]) {
666683
667684 sd_set_log_callback (sd_log_cb, (void *)¶ms);
668685
686+ server_log_params = (void *)¶ms;
687+
669688 if (params.verbose ) {
670689 print_params (params);
671690 printf (" %s" , sd_get_system_info ());
@@ -702,7 +721,8 @@ int main(int argc, const char* argv[]) {
702721 int n_prompts = 0 ;
703722
704723 const auto txt2imgRequest = [&sd_ctx, ¶ms, &n_prompts](const httplib::Request& req, httplib::Response& res) {
705- LOG_INFO (" raw body is: %s\n " , req.body .c_str ());
724+ // LOG_DEBUG("raw body is: %s\n", req.body.c_str());
725+ sd_log (sd_log_level_t ::SD_LOG_DEBUG, " raw body is: %s\n " , req.body .c_str ());
706726 // parse req.body as json using jsoncpp
707727 using json = nlohmann::json;
708728
@@ -720,9 +740,11 @@ int main(int argc, const char* argv[]) {
720740 }
721741 } catch (...) {
722742 // Handle any other type of exception
723- LOG_ERROR (" An unexpected error occurred\n " );
743+ // LOG_ERROR("An unexpected error occurred\n");
744+ sd_log (sd_log_level_t ::SD_LOG_ERROR, " An unexpected error occurred\n " , params);
724745 }
725- LOG_INFO (" prompt is: %s\n " , params.prompt .c_str ());
746+ // LOG_DEBUG("prompt is: %s\n", params.prompt.c_str());
747+ sd_log (sd_log_level_t ::SD_LOG_DEBUG, " prompt is: %s\n " , params.prompt .c_str ());
726748
727749 {
728750 sd_image_t * results;
0 commit comments