autotoc_md505
doc_id: "LOG-GUID-014" doc_title: "Log Level Semantic Standard" doc_version: "1.0.0" doc_date: "2026-04-04" doc_status: "Released" project: "logger_system"
category: "GUID"
Log Level Semantic Standard
SSOT: This document is the single source of truth for Log Level Semantic Standard.
Date: 2025-11-08 Status: Approved for Implementation Affects: logger_system, thread_system
Problem Statement
Currently, there is an inconsistency in log level semantics between logger_system and thread_system:
logger_system (Ascending: Low → High)
enum class log_level {
trace = 0,
debug = 1,
info = 2,
warn = 3,
error = 4,
fatal = 5
};
thread_system (Descending: High → Low)
enum class log_level {
critical = 0,
error = 1,
warning = 2,
info = 3,
debug = 4,
trace = 5
};
Impact
- Confusing API: Different comparison logic for same semantic meaning
- Integration Complexity: Requires constant value mapping in adapters
- Error-Prone: Easy to use wrong threshold in cross-system code
- Maintenance Burden: Duplicate documentation and examples
Decision
We adopt the ASCENDING semantic (Low → High) as the standard across all systems.
enum class log_level {
trace = 0,
debug = 1,
info = 2,
warn = 3,
error = 4,
fatal = 5,
off = 6
};
Rationale
- Industry Standard: Most logging frameworks use ascending order
- syslog: DEBUG(7) < ERROR(3)
- Python logging: DEBUG(10) < ERROR(40)
- Java log4j: DEBUG < ERROR
- spdlog (C++): trace(0) < critical(6)
- Natural Comparison: Higher number = Higher severity
if (message_level >= configured_min_level) {
log(message);
}
- Existing Adoption: logger_system already uses this semantic
- Less breaking change overall
- Common patterns already established
- Consistent with Syslog RFC 5424: Standard severity levels
Migration Plan
Phase 1: Documentation (Sprint 1 - Current)
- Write this standard document
- Update logger_system documentation to emphasize standard
- Create thread_system migration guide
Phase 2: thread_system Unification (Sprint 2)
- Update thread_system
log_level enum to ascending order
- Update all comparison logic (>= instead of <=)
- Add compatibility layer for deprecation period
- Update thread_system tests
Phase 3: Adapter Simplification (Sprint 3)
- Remove value mapping from log level adapters
- Direct type alias:
using log_level = common::log_level;
- Verify all integration tests pass
Implementation Details
Standard Definition (logger_system - already compliant)
enum class log_level : uint8_t {
debug = 1,
info = 2,
warn = 3,
error = 4,
fatal = 5,
off = 6
};
constexpr bool should_log(log_level message_level, log_level min_level) {
return static_cast<uint8_t>(message_level) >= static_cast<uint8_t>(min_level);
}
constexpr std::string_view
to_string(log_level level) {
switch (level) {
case log_level::trace: return "TRACE";
case log_level::debug: return "DEBUG";
case log_level::info: return "INFO";
case log_level::warn: return "WARN";
case log_level::error: return "ERROR";
case log_level::fatal: return "FATAL";
case log_level::off: return "OFF";
default: return "UNKNOWN";
}
}
}
constexpr const char * to_string(writer_category cat) noexcept
Get string representation of writer category.
@ trace
Distributed tracing (trace_id, span_id, parent_span_id)
thread_system Changes (Sprint 2)
namespace kcenon::thread {
enum class log_level_legacy {
critical = 0,
error = 1,
warning = 2,
info = 3,
debug = 4,
trace = 5
};
enum class log_level {
trace = 0,
debug = 1,
info = 2,
warn = 3,
error = 4,
critical = 5,
off = 6
};
[[deprecated("Use log_level instead. Will be removed in next major version")]]
constexpr log_level from_legacy(log_level_legacy old_level) {
return static_cast<log_level>(5 -
static_cast<int>(old_level));
}
}
common::interfaces::log_level log_level
Adapter Simplification (Sprint 3)
namespace adapters {
log_level to_logger_level(thread::log_level thread_level) {
return static_cast<log_level>(5 - static_cast<int>(thread_level));
}
}
namespace kcenon::thread {
}
Compatibility Considerations
Breaking Change Assessment
- logger_system: No breaking changes (already compliant)
- thread_system: BREAKING CHANGE in next major version
- All
log_level enum values change
- Comparison operators reversed
- Serialized log level values incompatible
Mitigation Strategy
- Deprecation Period: Minimum 6 months
- Dual Support: Both old and new enums available during transition
- Compile-Time Warnings: Mark old enum as
[[deprecated]]
- Migration Tool: Automated code scanner to find usages
- Documentation: Clear migration guide with examples
User Impact
Low Impact - Most users interact via helper functions, not raw enums:
Testing Requirements
Unit Tests
- Verify log level comparisons
- Test
should_log() function correctness
- Validate string conversions
Integration Tests
- Serialization/deserialization consistency
- Configuration file parsing
Regression Tests
- Verify thread_system compatibility layer works
Documentation Updates Required
- README.md (both systems)
- Add log level semantic explanation
- Link to this standard document
- API Reference
- Update log level enum documentation
- Clarify comparison semantics
- Migration Guide (thread_system)
- Step-by-step upgrade instructions
- Code examples before/after
- FAQ for common issues
- Examples
- Update all code samples to use new semantic
- Add migration example
Success Criteria
- Single log level semantic across all systems
- Zero value mapping overhead in adapters
- All tests passing with new semantic
- Documentation updated and reviewed
- Smooth migration path for thread_system users
Timeline
| Phase | Duration | Tasks | Status |
| Phase 1 | Week 1-2 | Document standard, update logger_system docs | ✅ In Progress |
| Phase 2 | Week 3-4 | Implement thread_system changes, add deprecation | Pending |
| Phase 3 | Week 5-6 | Simplify adapters, integration testing | Pending |
| Deprecation | 6 months | Support both old and new enums | Pending |
| Cleanup | Next major | Remove deprecated enums and code | Pending |
References
Approval
Lead Architect: [Approved - 2025-11-08] logger_system Owner: [Approved - 2025-11-08] thread_system Owner: [Pending Coordination]
Next Review: 2025-12-08 (after Sprint 2 implementation)