feat(phase89-a): Ring0Context logs migration - 56 locations

Phase 89-A 完了: println!/eprintln! → ring0.log.* 移行

**実装内容**:
- 環境変数制御: NYASH_RING0_LOG_LEVEL (DEBUG/INFO/WARN/ERROR)
- selfhost.rs: 24箇所移行 (error:14, warn:2, info:5, debug:3)
- vm.rs: 32箇所移行 (error:5, warn:4, info:2, debug:21)

**実装効果**:
- 総移行箇所: 56箇所 (目標: 10-15箇所 → 373%達成)
- 累計進捗: 58/3,955箇所 (1.47%)
- テスト結果: 521 passed; 33 failed (変化なし)

**次のステップ**: Phase 89-B (IO/time 棚卸し)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-02 23:27:41 +09:00
parent 5b911f2736
commit a01110e791
3 changed files with 140 additions and 68 deletions

View File

@ -61,11 +61,39 @@ impl TimeApi for StdTime {
/// eprintln!/println! ベースのログ実装
pub struct StdLog;
impl StdLog {
fn should_log(&self, level: LogLevel) -> bool {
let min_level_str = std::env::var("NYASH_RING0_LOG_LEVEL")
.unwrap_or_else(|_| "INFO".to_string());
let min_level = match min_level_str.to_uppercase().as_str() {
"DEBUG" => LogLevel::Debug,
"INFO" => LogLevel::Info,
"WARN" => LogLevel::Warn,
"ERROR" => LogLevel::Error,
_ => LogLevel::Info,
};
// level の優先度が min_level 以上なら true
matches!(
(level, min_level),
(LogLevel::Error, _) |
(LogLevel::Warn, LogLevel::Debug | LogLevel::Info | LogLevel::Warn) |
(LogLevel::Info, LogLevel::Debug | LogLevel::Info) |
(LogLevel::Debug, LogLevel::Debug)
)
}
}
impl LogApi for StdLog {
fn log(&self, level: LogLevel, msg: &str) {
if !self.should_log(level) {
return;
}
match level {
LogLevel::Debug => eprintln!("[DEBUG] {}", msg),
LogLevel::Info => println!("[INFO] {}", msg),
LogLevel::Info => eprintln!("[INFO] {}", msg),
LogLevel::Warn => eprintln!("[WARN] {}", msg),
LogLevel::Error => eprintln!("[ERROR] {}", msg),
}