nyash-json-plugin: - 796行の単一ファイルから6モジュール構造へ分割 - constants.rs, provider.rs, doc_box.rs, node_box.rs, tlv_helpers.rs, ffi.rsに責任分離 - 最大ファイルサイズを374行に削減(53%削減) - 共有状態管理をprovider.rsに集約 nyash-net-plugin: - 1112行の巨大ファイルから17ファイル構造へ分割 - boxesサブディレクトリでBox実装を整理(server, client, request, response, socket系) - 最大ファイルサイズを290行に削減(74%削減) - logging, tlv, http_helpers等の共通機能を独立モジュール化 両プラグインともビルド成功確認済み、完全な後方互換性を維持 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
26 lines
761 B
Rust
26 lines
761 B
Rust
use once_cell::sync::Lazy;
|
|
use std::fs::OpenOptions;
|
|
use std::io::Write as IoWrite;
|
|
use std::sync::Mutex;
|
|
|
|
static LOG_ON: Lazy<bool> = Lazy::new(|| std::env::var("NYASH_NET_LOG").unwrap_or_default() == "1");
|
|
static LOG_PATH: Lazy<String> = Lazy::new(|| {
|
|
std::env::var("NYASH_NET_LOG_FILE").unwrap_or_else(|_| "net_plugin.log".to_string())
|
|
});
|
|
static LOG_MTX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
|
|
|
pub(crate) fn net_log(msg: &str) {
|
|
if !*LOG_ON {
|
|
return;
|
|
}
|
|
eprintln!("[net] {}", msg);
|
|
let _g = LOG_MTX.lock().unwrap();
|
|
if let Ok(mut f) = OpenOptions::new()
|
|
.create(true)
|
|
.append(true)
|
|
.open(&*LOG_PATH)
|
|
{
|
|
let _ = writeln!(f, "[{:?}] {}", std::time::SystemTime::now(), msg);
|
|
}
|
|
}
|