MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / build_message

Method build_message

crates/opencode-util/src/logging.rs:94–122  ·  view source on GitHub ↗
(
        &self,
        level: LogLevel,
        message: &str,
        extra: Option<&HashMap<String, String>>,
    )

Source from the content-addressed store, hash-verified

92 }
93
94 fn build_message(
95 &self,
96 level: LogLevel,
97 message: &str,
98 extra: Option<&HashMap<String, String>>,
99 ) -> String {
100 let mut last = LAST_TIMESTAMP.lock().unwrap();
101 let now = Local::now();
102 let timestamp = now.format("%Y-%m-%dT%H:%M:%S").to_string();
103 let diff = now.timestamp_millis() - *last;
104 *last = now.timestamp_millis();
105 drop(last);
106
107 let mut parts = vec![timestamp, format!("+{}ms", diff)];
108
109 for (key, value) in &self.tags {
110 parts.push(format!("{}={}", key, value));
111 }
112
113 if let Some(extra) = extra {
114 for (key, value) in extra {
115 parts.push(format!("{}={}", key, value));
116 }
117 }
118
119 parts.push(message.to_string());
120
121 format!("{} {}\n", level, parts.join(" "))
122 }
123
124 pub fn debug(&self, message: &str, extra: Option<HashMap<String, String>>) {
125 if self.should_log(LogLevel::Debug) {

Callers 4

debugMethod · 0.80
infoMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected