Browse Source

Replace logging macros with std::cout for help text output

- Replace LOG_INFO macros in help text with std::cout statements
- Replace LOG_ERROR macros for help-related error messages with std::cout
- Add #include <iostream> for std::cout support
- Ensures help text is printed directly to stdout without going through logging system
Fszontagh 3 tháng trước cách đây
mục cha
commit
6d1ceeb8c2
1 tập tin đã thay đổi với 100 bổ sung100 xóa
  1. 100 100
      src/main.cpp

+ 100 - 100
src/main.cpp

@@ -1,6 +1,6 @@
-#include <csignal>
 #include <atomic>
 #include <chrono>
+#include <csignal>
 #include <filesystem>
 #include <iostream>
 #include <memory>
@@ -69,15 +69,15 @@ ServerConfig parseArguments(int argc, char* argv[]) {
     ServerConfig config;
 
     // Track which parameters were explicitly set
-    bool modelsDirSet        = false;
-    bool checkpointsSet      = false;
-    bool controlnetSet       = false;
-    bool embeddingsSet       = false;
-    bool esrganSet           = false;
-    bool loraSet             = false;
-    bool taesdSet            = false;
-    bool vaeSet              = false;
-    bool diffusionModelsSet  = false;
+    bool modelsDirSet       = false;
+    bool checkpointsSet     = false;
+    bool controlnetSet      = false;
+    bool embeddingsSet      = false;
+    bool esrganSet          = false;
+    bool loraSet            = false;
+    bool taesdSet           = false;
+    bool vaeSet             = false;
+    bool diffusionModelsSet = false;
 
     for (int i = 1; i < argc; i++) {
         std::string arg = argv[i];
@@ -189,99 +189,99 @@ ServerConfig parseArguments(int argc, char* argv[]) {
         } else if (arg == "--jwt-audience" && i + 1 < argc) {
             config.auth.jwtAudience = argv[++i];
         } else if (arg == "--help" || arg == "-h") {
-            LOG_INFO("stable-diffusion.cpp-rest server");
-            LOG_INFO("Usage: " + std::string(argv[0]) + " [options]");
-            LOG_INFO("");
-            LOG_INFO("Required Options:");
-            LOG_INFO("  --models-dir <dir>             Base models directory path (required)");
-            LOG_INFO("");
-            LOG_INFO("Server Options:");
-            LOG_INFO("  --host <host>                  Host address to bind to (default: 0.0.0.0)");
-            LOG_INFO("  --port <port>                  Port number to listen on (default: 8080)");
-            LOG_INFO("  --max-concurrent <num>         Maximum concurrent generations (default: 1)");
-            LOG_INFO("  --queue-dir <dir>              Queue persistence directory (default: ./queue)");
-            LOG_INFO("  --output-dir <dir>             Output files directory (default: ./output)");
-            LOG_INFO("  --ui-dir <dir>                 Web UI static files directory (optional)");
-            LOG_INFO("  --verbose, -v                  Enable verbose logging");
-            LOG_INFO("  --enable-file-logging          Enable logging to file");
-            LOG_INFO("  --log-file <path>              Log file path (default: /var/log/stable-diffusion-rest/server.log)");
-            LOG_INFO("");
-            LOG_INFO("Network & Connection Options:");
-            LOG_INFO("  --connection-timeout <ms>      Connection timeout in milliseconds (default: 500)");
-            LOG_INFO("  --read-timeout <ms>           Read timeout in milliseconds (default: 500)");
-            LOG_INFO("  --write-timeout <ms>          Write timeout in milliseconds (default: 500)");
-            LOG_INFO("");
-            LOG_INFO("Authentication Options:");
-            LOG_INFO("  --auth <method>                 Authentication method (none, jwt, api-key, unix, pam, optional)");
-            LOG_INFO("  --auth-method <method>          Authentication method (alias for --auth)");
-            LOG_INFO("  --jwt-secret <secret>           JWT secret key (auto-generated if not provided)");
-            LOG_INFO("  --jwt-expiration <minutes>      JWT token expiration time (default: 60)");
-            LOG_INFO("  --enable-guest-access          Allow unauthenticated guest access");
-            LOG_INFO("  --pam-service-name <name>      PAM service name (default: stable-diffusion-rest)");
-            LOG_INFO("  --auth-data-dir <dir>          Directory for authentication data (default: ./auth)");
-            LOG_INFO("  --public-paths <paths>         Comma-separated list of public paths (default: /api/health,/api/status)");
-            LOG_INFO("  --jwt-audience <audience>      JWT audience claim (default: stable-diffusion-rest)");
-            LOG_INFO("");
-            LOG_INFO("Deprecated Options (will be removed in future version):");
-            LOG_INFO("  --enable-unix-auth             Deprecated: Use --auth unix instead");
-            LOG_INFO("  --enable-pam-auth              Deprecated: Use --auth pam instead");
-            LOG_INFO("");
-            LOG_INFO("Model Directory Options:");
-            LOG_INFO("  All model directories are optional and default to standard folder names");
-            LOG_INFO("  under --models-dir. Only specify these if your folder names differ.");
-            LOG_INFO("");
-            LOG_INFO("  --checkpoints <dir>            Checkpoints directory (default: checkpoints)");
-            LOG_INFO("  --controlnet-dir <dir>         ControlNet models directory (default: controlnet)");
-            LOG_INFO("  --embeddings-dir <dir>         Embeddings directory (default: embeddings)");
-            LOG_INFO("  --esrgan-dir <dir>             ESRGAN models directory (default: ESRGAN)");
-            LOG_INFO("  --lora-dir <dir>               LoRA models directory (default: loras)");
-            LOG_INFO("  --taesd-dir <dir>              TAESD models directory (default: TAESD)");
-            LOG_INFO("  --vae-dir <dir>                VAE models directory (default: vae)");
-            LOG_INFO("  --diffusion-models-dir <dir>   Diffusion models directory (default: diffusion_models)");
-            LOG_INFO("");
-            LOG_INFO("Generation Limits & Security:");
-            LOG_INFO("  --max-prompt-length <len>      Maximum prompt character length (default: 10000)");
-            LOG_INFO("  --max-negative-prompt-length <len> Maximum negative prompt character length (default: 10000)");
-            LOG_INFO("  --shutdown-delay <ms>           Graceful shutdown delay in milliseconds (default: 100)");
-            LOG_INFO("");
-            LOG_INFO("Default Admin Credentials:");
-            LOG_INFO("  --default-admin-username <name> Default admin username (default: admin)");
-            LOG_INFO("  --default-admin-password <pass> Default admin password (default: admin123)");
-            LOG_INFO("  --default-admin-email <email>   Default admin email (default: admin@localhost)");
-            LOG_INFO("");
-            LOG_INFO("Model Management Options:");
-            LOG_INFO("  --hash-all-models              Hash all models in the models directory during startup");
-            LOG_INFO("                                  (blocks server startup until all models are hashed)");
-            LOG_INFO("");
-            LOG_INFO("Other Options:");
-            LOG_INFO("  --help, -h                     Show this help message");
-            LOG_INFO("");
-            LOG_INFO("Path Resolution:");
-            LOG_INFO("  - Absolute paths are used as-is");
-            LOG_INFO("  - Relative paths are resolved relative to --models-dir");
-            LOG_INFO("  - Default folder names match standard SD model structure");
-            LOG_INFO("");
-            LOG_INFO("Examples:");
-            LOG_INFO("  # Use all defaults (requires standard folder structure)");
-            LOG_INFO("  " + std::string(argv[0]) + " --models-dir /data/SD_MODELS");
-            LOG_INFO("");
-            LOG_INFO("  # Override specific folders");
-            LOG_INFO("  " + std::string(argv[0]) + " --models-dir /data/SD_MODELS --checkpoints my_checkpoints");
-            LOG_INFO("");
-            LOG_INFO("  # Use absolute path for one folder");
-            LOG_INFO("  " + std::string(argv[0]) + " --models-dir /data/SD_MODELS --lora-dir /other/path/loras");
+            std::cout << "stable-diffusion.cpp-rest server" << std::endl;
+            std::cout << "Usage: " << std::string(argv[0]) << " [options]" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Required Options:" << std::endl;
+            std::cout << "  --models-dir <dir>             Base models directory path (required)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Server Options:" << std::endl;
+            std::cout << "  --host <host>                  Host address to bind to (default: 0.0.0.0)" << std::endl;
+            std::cout << "  --port <port>                  Port number to listen on (default: 8080)" << std::endl;
+            std::cout << "  --max-concurrent <num>         Maximum concurrent generations (default: 1)" << std::endl;
+            std::cout << "  --queue-dir <dir>              Queue persistence directory (default: ./queue)" << std::endl;
+            std::cout << "  --output-dir <dir>             Output files directory (default: ./output)" << std::endl;
+            std::cout << "  --ui-dir <dir>                 Web UI static files directory (optional)" << std::endl;
+            std::cout << "  --verbose, -v                  Enable verbose logging" << std::endl;
+            std::cout << "  --enable-file-logging          Enable logging to file" << std::endl;
+            std::cout << "  --log-file <path>              Log file path (default: /var/log/stable-diffusion-rest/server.log)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Network & Connection Options:" << std::endl;
+            std::cout << "  --connection-timeout <ms>      Connection timeout in milliseconds (default: 500)" << std::endl;
+            std::cout << "  --read-timeout <ms>           Read timeout in milliseconds (default: 500)" << std::endl;
+            std::cout << "  --write-timeout <ms>          Write timeout in milliseconds (default: 500)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Authentication Options:" << std::endl;
+            std::cout << "  --auth <method>                 Authentication method (none, jwt, api-key, unix, pam, optional)" << std::endl;
+            std::cout << "  --auth-method <method>          Authentication method (alias for --auth)" << std::endl;
+            std::cout << "  --jwt-secret <secret>           JWT secret key (auto-generated if not provided)" << std::endl;
+            std::cout << "  --jwt-expiration <minutes>      JWT token expiration time (default: 60)" << std::endl;
+            std::cout << "  --enable-guest-access          Allow unauthenticated guest access" << std::endl;
+            std::cout << "  --pam-service-name <name>      PAM service name (default: stable-diffusion-rest)" << std::endl;
+            std::cout << "  --auth-data-dir <dir>          Directory for authentication data (default: ./auth)" << std::endl;
+            std::cout << "  --public-paths <paths>         Comma-separated list of public paths (default: /api/health,/api/status)" << std::endl;
+            std::cout << "  --jwt-audience <audience>      JWT audience claim (default: stable-diffusion-rest)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Deprecated Options (will be removed in future version):" << std::endl;
+            std::cout << "  --enable-unix-auth             Deprecated: Use --auth unix instead" << std::endl;
+            std::cout << "  --enable-pam-auth              Deprecated: Use --auth pam instead" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Model Directory Options:" << std::endl;
+            std::cout << "  All model directories are optional and default to standard folder names" << std::endl;
+            std::cout << "  under --models-dir. Only specify these if your folder names differ." << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "  --checkpoints <dir>            Checkpoints directory (default: checkpoints)" << std::endl;
+            std::cout << "  --controlnet-dir <dir>         ControlNet models directory (default: controlnet)" << std::endl;
+            std::cout << "  --embeddings-dir <dir>         Embeddings directory (default: embeddings)" << std::endl;
+            std::cout << "  --esrgan-dir <dir>             ESRGAN models directory (default: ESRGAN)" << std::endl;
+            std::cout << "  --lora-dir <dir>               LoRA models directory (default: loras)" << std::endl;
+            std::cout << "  --taesd-dir <dir>              TAESD models directory (default: TAESD)" << std::endl;
+            std::cout << "  --vae-dir <dir>                VAE models directory (default: vae)" << std::endl;
+            std::cout << "  --diffusion-models-dir <dir>   Diffusion models directory (default: diffusion_models)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Generation Limits & Security:" << std::endl;
+            std::cout << "  --max-prompt-length <len>      Maximum prompt character length (default: 10000)" << std::endl;
+            std::cout << "  --max-negative-prompt-length <len> Maximum negative prompt character length (default: 10000)" << std::endl;
+            std::cout << "  --shutdown-delay <ms>           Graceful shutdown delay in milliseconds (default: 100)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Default Admin Credentials:" << std::endl;
+            std::cout << "  --default-admin-username <name> Default admin username (default: admin)" << std::endl;
+            std::cout << "  --default-admin-password <pass> Default admin password (default: admin123)" << std::endl;
+            std::cout << "  --default-admin-email <email>   Default admin email (default: admin@localhost)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Model Management Options:" << std::endl;
+            std::cout << "  --hash-all-models              Hash all models in the models directory during startup" << std::endl;
+            std::cout << "                                  (blocks server startup until all models are hashed)" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Other Options:" << std::endl;
+            std::cout << "  --help, -h                     Show this help message" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Path Resolution:" << std::endl;
+            std::cout << "  - Absolute paths are used as-is" << std::endl;
+            std::cout << "  - Relative paths are resolved relative to --models-dir" << std::endl;
+            std::cout << "  - Default folder names match standard SD model structure" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "Examples:" << std::endl;
+            std::cout << "  # Use all defaults (requires standard folder structure)" << std::endl;
+            std::cout << "  " << std::string(argv[0]) << " --models-dir /data/SD_MODELS" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "  # Override specific folders" << std::endl;
+            std::cout << "  " << std::string(argv[0]) << " --models-dir /data/SD_MODELS --checkpoints my_checkpoints" << std::endl;
+            std::cout << "" << std::endl;
+            std::cout << "  # Use absolute path for one folder" << std::endl;
+            std::cout << "  " << std::string(argv[0]) << " --models-dir /data/SD_MODELS --lora-dir /other/path/loras" << std::endl;
             exit(0);
         } else {
-            LOG_ERROR("Unknown argument: " + arg);
-            LOG_ERROR("Use --help for usage information");
+            std::cout << "Unknown argument: " << arg << std::endl;
+            std::cout << "Use --help for usage information" << std::endl;
             exit(1);
         }
     }
 
     // Validate required parameters
     if (!modelsDirSet) {
-        LOG_ERROR("Error: --models-dir is required");
-        LOG_ERROR("Use --help for usage information");
+        std::cout << "Error: --models-dir is required" << std::endl;
+        std::cout << "Use --help for usage information" << std::endl;
         exit(1);
     }
 
@@ -470,7 +470,7 @@ int main(int argc, char* argv[]) {
             return 1;
         }
 
-if (config.verbose) {
+        if (config.verbose) {
             LOG_INFO("User manager initialized");
             std::string authMethod;
             switch (config.auth.authMethod) {
@@ -546,18 +546,18 @@ if (config.verbose) {
         // Hash all models if requested
         if (config.hashAllModels) {
             LOG_INFO("Hashing all models before starting server...");
-            
+
             // Progress callback for hashing
             auto hashProgressCallback = [](int current, int total, const std::string& modelName) {
                 // Use absolute path when printing to console
-                std::cout << "Hashing model " << current << " of " << total << ": " << modelName << std::endl;
+                LOG_INFO("Hashing model " + std::to_string(current) + " of " + std::to_string(total) + ": " + modelName);
             };
-            
+
             if (!modelManager->hashAllModels(hashProgressCallback)) {
                 LOG_ERROR("Failed to hash all models. Server will not start.");
                 return 1;
             }
-            
+
             LOG_INFO("All models hashed successfully. Starting server...");
         }