Skip to main content
Version: 2.5.0

Code Style

ChronoLog is a C++17 project. All formatting is enforced by clang-format-18 in CI — pull requests that don't pass the format check cannot be merged.

Formatting Tool

Install clang-format-18 from the default Ubuntu 24.04 repositories:

sudo apt-get update && sudo apt-get install -y clang-format-18

The project configuration lives at CodeStyleFiles/ChronoLog.clang-format. Key settings:

SettingValue
Column limit120 characters
Indent width4 spaces
TabsNever
Pointer alignmentLeft (int* p)
Brace wrappingAllman style (braces on their own line)
Sort includesNever (preserves intentional ordering)
Bin-pack arguments/parametersNo (one per line when wrapped)

Running Locally

Format a single file:

clang-format-18 -i -style=file:CodeStyleFiles/ChronoLog.clang-format path/to/file.cpp

Pre-commit Hook

The repository includes a ready-made hook at CodeStyleFiles/pre-commit that automatically formats staged C/C++ files before each commit. Install it by copying it into your local hooks directory:

cp CodeStyleFiles/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

The hook searches for clang-format-18 in ~/.local/bin, /usr/local/bin, /usr/bin, and $PATH. You can override the binary by setting the CLANG_FORMAT environment variable.

IDE Integration

CLion

  1. Go to File > Settings > Editor > Code Style > C/C++
  2. Click the gear icon and choose Import Scheme
  3. Import CodeStyleFiles/ChronoLog.xml

VS Code

Install the Clang-Format extension (or use clangd), then add to your workspace settings:

{
"C_Cpp.clang_format_path": "/usr/bin/clang-format-18",
"C_Cpp.clang_format_style": "file:${workspaceFolder}/CodeStyleFiles/ChronoLog.clang-format",
"editor.formatOnSave": true
}

Other Editors

Point your editor's clang-format integration at the CodeStyleFiles/ChronoLog.clang-format file and ensure it uses version 18. Different versions may produce different output.

CI Enforcement

The Clang Format Check workflow runs on every pull request that touches C/C++ files (.cpp, .h, .hpp, .cc, .cxx, .c). When formatting issues are found:

  1. The workflow posts a comment on your PR listing the affected files
  2. A clang-format-patches artifact is uploaded with patch files
  3. The check fails, blocking the PR

To fix a failed check:

# Option A: download and apply the patch artifact
gh run download <run-id> -n clang-format-patches
git apply format_fixes.patch

# Option B: format the files manually
clang-format-18 -i -style=file:CodeStyleFiles/ChronoLog.clang-format <file>

# Then commit and push
git add -u && git commit -m "style: fix formatting"
git push

Naming Conventions

ElementConventionExample
Classes / StructsPascalCaseStoryChunk, ChronoKeeperClient
Methods / FunctionscamelCaseacquireStory(), processEvent()
Member variablescamelCase, private members prefixed with thetheStoryId, theEventQueue
Local variablescamelCasestoryName, eventCount
EnumsPascalCase name, UPPER_CASE valuesenum class CLogStoryAcquisitionResult { CL_SUCCESS, CL_ERR_UNKNOWN }
Typedefs / AliasesPascalCaseStoryId, ChunkMap
Namespaceslowercasechronolog
Header guards#ifndef with full path#ifndef CHRONO_COMMON_CHRONOLOG_ERRCODE_H
Constants / MacrosUPPER_CASEMAX_STORY_CHUNK_SIZE

Error Handling and Logging

Error Codes

ChronoLog uses integer error codes defined in chrono_common/include/chronolog_errcode.h. Return CL_SUCCESS (0) on success and negative values on failure. The file provides to_string() conversion functions for human-readable log output.

Logging

ChronoLog uses spdlog through wrapper macros:

MacroUse
LOG_TRACE(...)Verbose debugging (off in release)
LOG_DEBUG(...)Developer-facing diagnostics
LOG_INFO(...)Normal operational messages
LOG_WARNING(...)Unexpected but recoverable situations
LOG_ERROR(...)Failures that affect a single operation
LOG_CRITICAL(...)Unrecoverable errors

Additional Static Analysis

The CMake build includes a cpplint target for additional style checking. This is not enforced in CI but can be useful during development:

cmake --build build --target cpplint