Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:42:58.257Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

json_log.rs

62 lines · 1.7 KB · rust
1use std::borrow::Cow;
2
3use log::{Level, Log, Record};
4use serde::{Deserialize, Serialize};
5
6#[derive(Deserialize, Debug, Serialize)]
7pub struct LogRecord<'a> {
8    pub level: usize,
9    pub module_path: Option<Cow<'a, str>>,
10    pub file: Option<Cow<'a, str>>,
11    pub line: Option<u32>,
12    pub message: Cow<'a, str>,
13}
14
15impl<'a> LogRecord<'a> {
16    pub fn new(record: &'a Record<'a>) -> Self {
17        Self {
18            level: serialize_level(record.level()),
19            module_path: record.module_path().map(Cow::Borrowed),
20            file: record.file().map(Cow::Borrowed),
21            line: record.line(),
22            message: Cow::Owned(record.args().to_string()),
23        }
24    }
25
26    pub fn log(&'a self, logger: &dyn Log) {
27        if let Some(level) = deserialize_level(self.level) {
28            logger.log(
29                &log::Record::builder()
30                    .module_path(self.module_path.as_deref())
31                    .target("remote_server")
32                    .args(format_args!("{}", self.message))
33                    .file(self.file.as_deref())
34                    .line(self.line)
35                    .level(level)
36                    .build(),
37            )
38        }
39    }
40}
41
42fn serialize_level(level: Level) -> usize {
43    match level {
44        Level::Error => 1,
45        Level::Warn => 2,
46        Level::Info => 3,
47        Level::Debug => 4,
48        Level::Trace => 5,
49    }
50}
51
52fn deserialize_level(level: usize) -> Option<Level> {
53    match level {
54        1 => Some(Level::Error),
55        2 => Some(Level::Warn),
56        3 => Some(Level::Info),
57        4 => Some(Level::Debug),
58        5 => Some(Level::Trace),
59        _ => None,
60    }
61}
62
Served at tenant.openagents/omega Member data and write actions are omitted.