-
Notifications
You must be signed in to change notification settings - Fork 8
Move logging initialization into Fastly adapter (PR 10) #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prk-Jr
wants to merge
11
commits into
feature/edgezero-pr9-wire-signing-to-store-primitives
Choose a base branch
from
feature/edgezero-pr10-abstract-logging-initialization
base: feature/edgezero-pr9-wire-signing-to-store-primitives
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7310198
Add PR 10 logging initialization design
prk-Jr a05189e
Add PR 10 logging initialization plan
prk-Jr 4617253
Fix PR 10 logging plan to avoid per-log allocation
prk-Jr 236eecf
Extract Fastly logging initialization into adapter module
prk-Jr cd68357
Wire Fastly main.rs to adapter-local logging module
prk-Jr 41cb0df
Remove log-fastly from core dependencies
prk-Jr e437454
Format Fastly logging module declaration
prk-Jr f9b4d62
format plan docs
prk-Jr 49e3f1d
Restore idiomatic fern logging and improve target label extraction
prk-Jr dd6929c
Resolve review findings
prk-Jr 1acbfa7
Resolve PR review feedback on logging module
prk-Jr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use chrono::{SecondsFormat, Utc}; | ||
| use log_fastly::Logger; | ||
|
|
||
| /// Extracts the final `::` segment from a Rust module path for use as a log label. | ||
| /// | ||
| /// Falls back to the full target string when the input contains no separator or | ||
| /// when the separator appears at the trailing position (e.g. `"foo::"`), which | ||
| /// would otherwise produce an empty label in log output. | ||
| fn target_label(target: &str) -> &str { | ||
| match target.rsplit_once("::") { | ||
| Some((head, "")) => head, | ||
| Some((_, last)) => last, | ||
| None => target, | ||
| } | ||
| } | ||
|
|
||
| /// Initialises the Fastly-backed `fern` logger and installs it as the global logger. | ||
| /// | ||
| /// Log records are forwarded to the `tslog` Fastly endpoint and echoed to stdout. | ||
| /// Each line is prefixed with an RFC 3339 timestamp, level, and the final segment | ||
| /// of the record's target module path. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the logger cannot be built or if a global logger has already been set. | ||
| pub(crate) fn init_logger() { | ||
| let logger = Logger::builder() | ||
| .default_endpoint("tslog") | ||
| .echo_stdout(true) | ||
| .max_level(log::LevelFilter::Info) | ||
| .build() | ||
| .expect("should build Logger"); | ||
|
|
||
| fern::Dispatch::new() | ||
| .format(|out, message, record| { | ||
| out.finish(format_args!( | ||
| "{} {} [{}] {}", | ||
| Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true), | ||
| record.level(), | ||
| target_label(record.target()), | ||
| message | ||
| )); | ||
| }) | ||
| .chain(Box::new(logger) as Box<dyn log::Log>) | ||
| .apply() | ||
| .expect("should initialize logger"); | ||
| } | ||
|
prk-Jr marked this conversation as resolved.
|
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn target_label_extracts_correct_segment() { | ||
| assert_eq!( | ||
|
prk-Jr marked this conversation as resolved.
|
||
| target_label("trusted_server_adapter_fastly::proxy"), | ||
| "proxy", | ||
| "should handle standard single-separator case" | ||
| ); | ||
| assert_eq!( | ||
| target_label("foo::bar::baz"), | ||
| "baz", | ||
| "should handle multiple separators" | ||
| ); | ||
| assert_eq!( | ||
| target_label("no_separators_here"), | ||
| "no_separators_here", | ||
| "should handle inputs without ::" | ||
| ); | ||
| assert_eq!(target_label(""), "", "should handle empty strings"); | ||
| assert_eq!( | ||
| target_label("trailing::"), | ||
| "trailing", | ||
| "should strip separator when trailing segment is empty" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.