@@ -302,52 +302,55 @@ cd build && ctest
302302
303303### Configuring Log Levels
304304
305- AI SDK C++ uses [ spdlog ] ( https://github.com/gabime/spdlog ) for logging.
305+ AI SDK C++ uses a built-in logging system defined in ` ai/logger.h ` .
306306
307307### Setting Log Levels
308308
309- You can control the logging verbosity by setting the spdlog level in your application:
309+ You can control the logging verbosity by configuring the logger in your application:
310310
311311``` cpp
312- #include < spdlog/spdlog.h >
312+ #include " ai/logger.h "
313313
314314// In your main() or initialization code:
315315
316316// Enable debug logging (most verbose)
317- spdlog::set_level (spdlog::level::debug);
317+ ai::logger::install_logger (
318+ std::make_shared<ai::logger::ConsoleLogger>(ai::logger::LogLevel::kLogLevelDebug)
319+ );
318320
319321// Enable info logging (operational information)
320- spdlog::set_level(spdlog::level::info);
322+ ai::logger::install_logger (
323+ std::make_shared<ai::logger::ConsoleLogger>(ai::logger::LogLevel::kLogLevelInfo)
324+ );
321325
322326// Enable warning logging (default)
323- spdlog::set_level(spdlog::level::warn);
327+ ai::logger::install_logger (
328+ std::make_shared<ai::logger::ConsoleLogger>(ai::logger::LogLevel::kLogLevelWarn)
329+ );
324330
325331// Enable error logging only
326- spdlog::set_level(spdlog::level::err);
332+ ai::logger::install_logger (
333+ std::make_shared<ai::logger::ConsoleLogger>(ai::logger::LogLevel::kLogLevelError)
334+ );
327335```
328336
329337### Available Log Levels
330338
331339From most to least verbose:
332340
333- 1. **trace**: Most detailed information (not commonly used in AI SDK)
334- 2. **debug**: Detailed flow information, request/response bodies, connection details
335- 3. **info**: Important operational events (successful completions, stream events)
336- 4. **warn**: Warning conditions that don't prevent operation
337- 5. **err**: Error conditions and exceptions
338- 6. **critical**: Critical failures (not commonly used in AI SDK)
339- 7. **off**: Disable all logging
341+ 1 . ** debug** : Detailed flow information, request/response bodies, connection details
342+ 2 . ** info** : Important operational events (successful completions, stream events)
343+ 3 . ** warn** : Warning conditions that don't prevent operation
344+ 4 . ** error** : Error conditions and exceptions
340345
341- ### Environment Variable Configuration
346+ ### Null Logger
342347
343- You can also set the log level via environment variable :
348+ To disable all logging, you can install a null logger :
344349
345- ```bash
346- # Enable debug logging
347- export SPDLOG_LEVEL=debug
348-
349- # Enable info logging
350- export SPDLOG_LEVEL=info
350+ ``` cpp
351+ ai::logger::install_logger (
352+ std::make_shared<ai::logger::NullLogger>()
353+ );
351354```
352355
353356### Example Log Output
@@ -374,25 +377,44 @@ With **info** level enabled:
374377
375378### Custom Logger Configuration
376379
377- For more advanced logging configurations :
380+ You can create your own logger by implementing the ` ai::logger::Logger ` interface :
378381
379382``` cpp
380- #include < spdlog/spdlog.h>
381- #include < spdlog/sinks/basic_file_sink.h>
382- #include < spdlog/sinks/stdout_color_sinks.h>
383-
384- // Create a multi-sink logger (console + file)
385- auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
386- auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(" ai_sdk.log" , true );
387-
388- std::vector<spdlog::sink_ptr> sinks {console_sink, file_sink};
389- auto logger = std::make_shared< spdlog::logger > ("ai_sdk", sinks.begin(), sinks.end());
390-
391- // Set as default logger
392- spdlog::set_default_logger (logger);
383+ #include " ai/logger.h"
384+ #include < fstream>
385+
386+ class FileLogger : public ai ::logger::Logger {
387+ public:
388+ FileLogger(const std::string& filename)
389+ : file_ (filename, std::ios::app) {}
390+
391+ void log(ai::logger::LogLevel level, std::string_view message) override {
392+ if (is_enabled(level)) {
393+ file_ << "[ " << level_to_string(level) << "] " << message << std::endl;
394+ }
395+ }
396+
397+ bool is_enabled(ai::logger::LogLevel level) const override {
398+ return level >= min_level_ ;
399+ }
400+
401+ private:
402+ std::ofstream file_ ;
403+ ai::logger::LogLevel min_level_ = ai::logger::LogLevel::kLogLevelInfo;
404+
405+ static std::string_view level_to_string(ai::logger::LogLevel level) {
406+ switch (level) {
407+ case ai::logger::LogLevel::kLogLevelDebug: return "DEBUG";
408+ case ai::logger::LogLevel::kLogLevelInfo: return "INFO";
409+ case ai::logger::LogLevel::kLogLevelWarn: return "WARN";
410+ case ai::logger::LogLevel::kLogLevelError: return "ERROR";
411+ }
412+ return "UNKNOWN";
413+ }
414+ };
393415
394- // Configure format
395- spdlog::set_pattern (" [ %Y-%m-%d %H:%M:%S.%e ] [ %l ] [ %t ] %v" );
416+ // Install custom logger
417+ ai::logger::install_logger(std::make_shared< FileLogger >("ai_sdk.log") );
396418```
397419
398420### Development Recommendations
@@ -417,7 +439,9 @@ class AITestFixture : public ::testing::Test {
417439protected:
418440 void SetUp() override {
419441 // Enable debug logging for tests
420- spdlog::set_level(spdlog::level::debug);
442+ ai::logger::install_logger(
443+ std::make_shared< ai::logger::ConsoleLogger > (ai::logger::LogLevel::kLogLevelDebug)
444+ );
421445 }
422446};
423447```
@@ -430,7 +454,7 @@ Managed via `vcpkg.json`:
430454
431455- **fmt**: Fast formatting library
432456- **nlohmann-json**: JSON parsing and generation
433- - **spdlog **: Fast logging library
457+ - **Built-in logging **: ai::logger provides flexible logging capabilities
434458- **cpp-httplib**: HTTP client library with OpenSSL and Brotli support
435459- **openssl**: Cryptographic library
436460
0 commit comments