MCPcopy Create free account
hub / github.com/awslabs/llrt / write_lambda_log

Function write_lambda_log

llrt_core/src/modules/console.rs:176–328  ·  view source on GitHub ↗
(
    ctx: &Ctx<'js>,
    result: &mut String,
    args: Rest<Value<'js>>,
    level: LogLevel,
    is_tty: bool,
    is_json_log_format: bool,
    max_log_level: usize,
    time_format: &str,
)

Source from the content-addressed store, hash-verified

174#[inline(always)]
175#[allow(clippy::too_many_arguments)]
176fn write_lambda_log<'js>(
177 ctx: &Ctx<'js>,
178 result: &mut String,
179 args: Rest<Value<'js>>,
180 level: LogLevel,
181 is_tty: bool,
182 is_json_log_format: bool,
183 max_log_level: usize,
184 time_format: &str,
185) -> Result<bool> {
186 let mut is_newline = true;
187
188 //do not log if we don't meet the log level
189 if is_json_log_format && (level.clone() as usize) < max_log_level {
190 return Ok(false);
191 }
192 result.reserve(64);
193 if !is_tty {
194 is_newline = false;
195 }
196
197 let current_time = Timestamp::now();
198 let formatted_time = current_time.strftime(time_format);
199 let request_id = runtime_client::LAMBDA_REQUEST_ID.read().unwrap();
200
201 if is_json_log_format {
202 result.push('{');
203 //time
204 result.push_str("\"time\":\"");
205 write!(result, "{}", formatted_time).unwrap();
206 result.push_str("\",");
207
208 //request id
209 if let Some(id) = request_id.as_ref() {
210 result.push_str("\"requestId\":\"");
211 result.push_str(id);
212 result.push_str("\",");
213 }
214
215 //level
216 result.push_str("\"level\":\"");
217 result.push_str(&level.to_string());
218 result.push('\"');
219 } else {
220 write!(result, "{}", formatted_time).unwrap();
221 result.push('\t');
222
223 match request_id.as_ref() {
224 Some(id) => result.push_str(id),
225 None => result.push_str("n/a"),
226 }
227
228 result.push('\t');
229 result.push_str(&level.to_string());
230 result.push('\t');
231 }
232
233 if is_json_log_format {

Callers 3

write_logFunction · 0.85
json_log_formatFunction · 0.85
standard_log_formatFunction · 0.85

Calls 15

get_class_nameFunction · 0.85
fromFunction · 0.85
json_stringifyFunction · 0.85
build_formatted_stringFunction · 0.85
escape_jsonFunction · 0.85
pushMethod · 0.80
firstMethod · 0.80
messageMethod · 0.80
stackMethod · 0.80
readMethod · 0.65
cloneMethod · 0.45

Tested by

no test coverage detected