You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lambda-runtime-api-client/src/tracing.rs
+16-5
Original file line number
Diff line number
Diff line change
@@ -15,14 +15,25 @@ pub use tracing::*;
15
15
/// Re-export the `tracing-subscriber` crate to build your own subscribers.
16
16
pubuse tracing_subscriber as subscriber;
17
17
18
-
/// Initialize `tracing-subscriber` with default options.
19
-
/// The subscriber uses `AWS_LAMBDA_LOG_LEVEL` as the environment variable to determine the log level for your function.
20
-
/// It also uses [Lambda's advance logging controls](https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/)
18
+
constDEFAULT_LOG_LEVEL:&str = "INFO";
19
+
20
+
/// Initialize `tracing-subscriber` with default logging options.
21
+
///
22
+
/// This function uses environment variables set with [Lambda's advance logging controls](https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/)
21
23
/// if they're configured for your function.
22
-
/// By default, the log level to emit events is `INFO`.
24
+
///
25
+
/// This subscriber sets the logging level based on environment variables:
26
+
/// - if `AWS_LAMBDA_LOG_LEVEL` is set, it takes predecence over any other environment variables.
27
+
/// - if `AWS_LAMBDA_LOG_LEVEL` is not set, check if `RUST_LOG` is set.
28
+
/// - if none of those two variables are set, use `INFO` as the logging level.
29
+
///
30
+
/// The logging format can also be changed based on Lambda's advanced logging controls.
31
+
/// If the `AWS_LAMBDA_LOG_FORMAT` environment variable is set to `JSON`, the log lines will be formatted as json objects,
32
+
/// otherwise they will be formatted with the default tracing format.
23
33
pubfninit_default_subscriber(){
24
34
let log_format = env::var("AWS_LAMBDA_LOG_FORMAT").unwrap_or_default();
25
-
let log_level = Level::from_str(&env::var("AWS_LAMBDA_LOG_LEVEL").unwrap_or_default()).unwrap_or(Level::INFO);
35
+
let log_level_str = env::var("AWS_LAMBDA_LOG_LEVEL").or_else(|_| env::var("RUST_LOG"));
36
+
let log_level = Level::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(Level::INFO);
0 commit comments