Skip to content

feat: allow log output to a file#252

Merged
16bit-ykiko merged 13 commits into
mainfrom
log-format
Sep 14, 2025
Merged

feat: allow log output to a file#252
16bit-ykiko merged 13 commits into
mainfrom
log-format

Conversation

@16bit-ykiko

@16bit-ykiko 16bit-ykiko commented Sep 9, 2025

Copy link
Copy Markdown
Member
  1. add spdlog
  2. use spdlog::info and spdlog::warn
  3. clean old log options

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @16bit-ykiko, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates the spdlog library into the project's build systems and migrates existing logging calls to use spdlog. This change enhances the application's logging capabilities, enabling more flexible output options and improved log management, which is a foundational step towards allowing log output to a file.

Highlights

  • New Logging Library Integration: The spdlog library has been integrated into the project, replacing the previous custom log:: calls.
  • Build System Updates: Both CMakeLists.txt and xmake.lua have been updated to fetch, build, and link spdlog as a dependency.
  • Logging Call Migration: All instances of log::info in src/Driver/clice.cc have been replaced with spdlog::info, standardizing the logging interface.
  • Initial Logger Configuration: The default spdlog logger is now configured to output to stderr with color support, laying the groundwork for more flexible logging destinations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the project's logging from a custom implementation to spdlog. The changes correctly add spdlog as a dependency in the build systems. However, the migration is incomplete: some calls to the old logger remain, and the command-line options for configuring log level and color are now broken because they affect the old logger. There is also a potential bug in CMakeLists.txt where flags are appended without a space. Finally, the PR title mentions file logging, which doesn't seem to be implemented yet; the new logger only writes to stderr.

Comment thread CMakeLists.txt Outdated
Comment thread src/Driver/clice.cc
@16bit-ykiko

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces spdlog to replace the existing custom logging implementation, which is a great improvement. The changes are well-executed, including adding the dependency in both CMake and xmake, creating a new logger wrapper that utilizes modern C++ features like std::source_location, and consistently updating logging calls throughout the codebase. The refactoring of command-line options to use enums also significantly improves code quality and type safety. I've provided a few suggestions to further enhance the new logging implementation and maintain consistency.

Comment thread include/Support/Logger.h
Comment thread include/Support/Logger.h
Comment thread src/Driver/clice.cc
Comment thread src/Driver/clice.cc
@16bit-ykiko

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully integrates spdlog to replace the custom logging implementation, which is a great improvement. The changes are mostly clean, replacing old logger calls with the new spdlog wrappers. The command-line option handling for logging levels and server mode has also been refactored to use enums, improving type safety and code clarity. I've identified a critical bug in the new file logging functionality that prevents logs from being written to the correct directory. Additionally, I have a suggestion to improve the consistency of logging levels for fatal errors. Overall, this is a solid refactoring with a couple of issues to address.

Comment thread src/Support/Logging.cpp Outdated
Comment thread include/Support/Logging.h
Comment thread src/Driver/clice.cc
@16bit-ykiko

Copy link
Copy Markdown
Member Author

/gemini summary

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request significantly refactors the project's logging infrastructure by replacing a custom logging solution with the spdlog library. This change introduces robust file logging capabilities, improves log configuration through command-line options, and standardizes logging practices across the codebase. The migration ensures more efficient and configurable log output, which is crucial for debugging and operational insights.

Highlights

  • Logging Library Migration: The custom logging implementation (Support/Logger.h) has been replaced with the spdlog library, a fast, header-only C++ logging library.
  • File Logging Capability: The system now supports outputting logs to a file, providing more flexible logging options for debugging and monitoring.
  • Enhanced Log Configuration: Command-line arguments (--log-level, --log-color) have been updated to directly control spdlog's behavior, including support for various log levels and colored output.
  • Codebase-wide Logging Update: All existing logging calls across the codebase have been migrated from the old log:: namespace to the new logging:: namespace, utilizing spdlog's features.
  • Build System Integration: spdlog has been integrated into both the CMake and xmake build systems, ensuring its dependencies are fetched and correctly linked, along with necessary compile definitions.
Changelog
  • CMakeLists.txt
    • Added conditional libc++ flags for C++ standard library linking.
    • Integrated spdlog (v1.15.3) as a FetchContent dependency.
    • Configured spdlog with BUILD_SHARED_LIBS OFF and compile definitions SPDLOG_USE_STD_FORMAT=1 and SPDLOG_NO_EXCEPTIONS=1.
    • Linked spdlog::spdlog to the clice-core target.
    • Removed redundant libc++ flag handling.
    • Added TOML_EXCEPTIONS=0 compile definition to clice-core.
  • include/Async/Network.h
    • Removed the declaration of the spawn function.
  • include/Async/libuv.h
    • Updated include directive from Support/Logger.h to Support/Logging.h.
  • include/Support/Logger.h
    • File removed as part of the logging library migration.
  • include/Support/Logging.h
    • New file added, providing spdlog wrappers, Level enum, Options struct, and declarations for create_stderr_logger and create_file_loggger.
    • Introduced logging_format for capturing source location information in log calls.
  • src/AST/Selection.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::debug calls with logging::debug.
  • src/Async/FileSystem.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::warn calls with logging::warn.
  • src/Async/Network.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::fatal and log::warn calls with logging::fatal and logging::warn.
    • Removed the implementation of the spawn function.
  • src/Async/libuv.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::warn calls with logging::warn.
  • src/Compiler/Command.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::warn and log::info calls with logging::warn and logging::info.
  • src/Compiler/Preamble.cpp
    • Updated include to Support/Logging.h.
  • src/Driver/clice.cc
    • Updated include to Support/Logging.h.
    • Changed the mode command-line option to an enum type.
    • Updated the log_level command-line option to use the new logging::Level enum and spdlog levels.
    • Modified init_log to configure spdlog based on command-line options and call logging::create_stderr_logger.
    • Renamed checkArguments to check_arguments.
    • Updated all log::info and log::fatal calls to logging::info and logging::fatal.
    • Refactored server mode selection logic using a switch statement.
  • src/Driver/unit_tests.cc
    • Reformated command-line option declarations for consistency.
  • src/Feature/Diagnostic.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::info calls with logging::info.
  • src/Feature/Formatting.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::info calls with logging::info.
  • src/Server/Config.cpp
    • Updated includes to Support/Logging.h and Support/FileSystem.h.
    • Replaced log::info calls with logging::info.
  • src/Server/Document.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::warn, log::info, and log::fatal calls with logging::warn, logging::info, and logging::fatal.
  • src/Server/Indexer.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::info calls with logging::info.
  • src/Server/Lifecycle.cpp
    • Replaced log::info and log::fatal calls with logging::info and logging::fatal.
  • src/Server/Server.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::fatal, log::warn, and log::info calls with logging::fatal, logging::warn, and logging::info.
  • src/Support/Logging.cpp
    • New file added, implementing logging::options, create_stderr_logger, and create_file_loggger using spdlog sinks.
  • tests/unit/Index/USR.cpp
    • Updated include to Support/Logging.h.
    • Replaced log::info and log::fatal calls with logging::info and logging::fatal.
  • xmake.lua
    • Added spdlog as a requirement with specific options (header_only=n,std_format,noexcept).
    • Defined TOML_EXCEPTIONS=0.
    • Added spdlog to the target("clice-core") packages.
Activity
  • A bot comment highlighted the need for leading spaces when appending to CMake flag strings (e.g., CMAKE_CXX_FLAGS) to ensure proper flag separation. This was addressed in the patch.
  • A bot pointed out that the init_log() function was still configuring the old custom logger, making new spdlog command-line options ineffective. It suggested updating init_log() to configure spdlog and removing the old logger. This was addressed in the patch.
  • A bot suggested simplifying an if constexpr block in include/Support/Logging.h as one branch would always be taken. This specific simplification was not applied in the current patch.
  • A bot recommended using spdlog::level::critical for fatal errors and calling spdlog::shutdown() before std::exit(1) for proper log flushing. The patch uses spdlog::level::err for fatal, so this was partially addressed (shutdown added, but level not changed to critical).
  • A bot suggested mapping the fatal command-line option to logging::Level::critical for consistency. The patch maps fatal to logging::Level::err, so this was not fully addressed.
  • A bot advised changing the logging level for command-line arguments from info to debug to reduce verbosity. The patch changed log::info to logging::info, so this was not addressed.
  • A bot identified a critical issue where create_file_loggger was using only the filename instead of the full path, causing log files to be created in the wrong directory. The patch's implementation of create_file_loggger in src/Support/Logging.cpp correctly uses the full path variable, so this was addressed.
  • Two more bot comments reiterated the need to use spdlog::level::critical for the fatal logging function and its command-line mapping. These were not addressed in the patch.

@16bit-ykiko 16bit-ykiko merged commit e8f5f6b into main Sep 14, 2025
9 checks passed
@16bit-ykiko 16bit-ykiko deleted the log-format branch September 14, 2025 08:45
@16bit-ykiko 16bit-ykiko changed the title Allow log output to a file feat: allow log output to a file Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants