-
-
Notifications
You must be signed in to change notification settings - Fork 294
Local Tz logs #1296
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
base: main
Are you sure you want to change the base?
Local Tz logs #1296
Conversation
📝 WalkthroughWalkthroughThe Cargo.toml for server adds the "chrono" feature to the tracing-subscriber dependency. server/src/logging.rs reworks initialization: the registry starts with EnvFilter and now unconditionally attaches a fmt layer using ChronoLocal::rfc_3339() for RFC3339 local timestamps. Prior environment-variable branching (LLDAP_LOCAL_TZ_LOG / LLDAP_RAW_LOG) and ForestLayer wiring were removed (ForestLayer left as a TODO). The public API remains unchanged: Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
server/src/logging.rs (4)
50-52: Env toggles: consider cheaper presence check and document precedence
- Minor: prefer
env::var_os(...).is_some()to avoid allocating aString.- Please document that
LLDAP_LOCAL_TZ_LOGwins overLLDAP_RAW_LOGwhen both are set.Apply this minimal tweak if desired:
- let raw_logs = env::var("LLDAP_RAW_LOG").is_ok(); - let local_tz = env::var("LLDAP_LOCAL_TZ_LOG").is_ok(); + let raw_logs = std::env::var_os("LLDAP_RAW_LOG").is_some(); + let local_tz = std::env::var_os("LLDAP_LOCAL_TZ_LOG").is_some();
53-61: Avoid panics: usetry_init()instead ofinit()
init()panics if the global subscriber is already set (e.g., tests initializing twice). Propagate the error instead.Apply this diff:
- registry - .with(tracing_subscriber::fmt::layer().with_timer(ChronoLocal::rfc_3339())) - .init(); + registry + .with(tracing_subscriber::fmt::layer().with_timer(ChronoLocal::rfc_3339())) + .try_init()?; @@ - registry.with(tracing_subscriber::fmt::layer()).init(); + registry.with(tracing_subscriber::fmt::layer()).try_init()?; @@ - registry.with(tracing_forest::ForestLayer::default()).init(); + registry.with(tracing_forest::ForestLayer::default()).try_init()?;
53-61: Ops note: ensure tzdata in container imagesLocal timestamps rely on the container’s timezone data (TZ or /etc/localtime). If tzdata is missing (common on Alpine/musl minimal images), offsets can be wrong/unknown. Consider documenting this in the Docker README.
53-61: Keep Forest formatting with local timestamps — enable tracing-forest's chrono featuretracing-forest v0.1.6 exposes an optional "chrono" feature (or "full") that emits timestamps via Chrono and will reflect the process/container local timezone; enable it in Cargo.toml and continue using ForestLayer for the local_tz branch instead of switching to tracing_subscriber::fmt::layer. File: server/src/logging.rs (lines 53–61). Add to Cargo.toml: tracing-forest = { version = "0.1.6", features = ["chrono"] } (or features = ["full"]).
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
server/Cargo.toml(1 hunks)server/src/logging.rs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-14T13:45:50.380Z
Learnt from: CR
PR: lldap/lldap#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T13:45:50.380Z
Learning: Applies to server/Cargo.toml : Add backend server dependencies in /server/Cargo.toml
Applied to files:
server/Cargo.toml
🔇 Additional comments (3)
server/Cargo.toml (1)
70-73: Enabletracing-subscriberchrono feature — LGTMMatches the new
ChronoLocalusage in logging.rs; feature‑gating is correct and keeps “local-time” disabled as intended.server/src/logging.rs (2)
9-11: Imports forChronoLocaland init helpers — LGTMThe import set aligns with the new timer and init path.
48-48: Build registry first, attach a single layer later — LGTMClean separation; avoids stacking multiple formatters inadvertently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check how timestamps (e.g. creation time) get printed? Does it get turned into the local timezone?
server/src/logging.rs
Outdated
| if env::var("LLDAP_RAW_LOG").is_ok() { | ||
| let registry = tracing_subscriber::registry().with(env_filter); | ||
|
|
||
| let raw_logs = env::var("LLDAP_RAW_LOG").is_ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a temporary workaround that I haven't gotten around to cleaning up, but it should go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to explain what kind of workaround this was I can try to fix it for you so this PRs contains the final clean code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, assume it's always false and that's the cleanup :)
Implied being that whatever logging solution we end up with, I'd like it to work with tracing forest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, a real cleanup then 👍
But it seems like tracing_forest doesn't support .with_timer as it is only available from the bare Layer struct of tracing_subscriber and no equivalent seems to exist.
I believe this is a blocker ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a blocker for me.
We can raise an issue with the crate, they're really nice guys and reactive.
Before we go much further though, I'd like to know how you plan on addressing the creation_date problem (timestamps in structs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't look that far yet as the blocker was really evident.
I'll check and see for myself asap, for now I can't seem to get the webui to show up after a cargo run run which is odd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you build the frontend? ./app/build.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found it a few seconds ago 👍
server/src/logging.rs
Outdated
| let registry = tracing_subscriber::registry().with(env_filter); | ||
|
|
||
| let raw_logs = env::var("LLDAP_RAW_LOG").is_ok(); | ||
| let local_tz = env::var("LLDAP_LOCAL_TZ_LOG").is_ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced by this approach: I think the logs should always default to the local timezone (and you can control that with standard environment variables) if we don't want to log in UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I assumed you'd want UTC by default 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
server/src/logging.rs (1)
48-53: Prefertry_init()overinit()to avoid panics on double initialization (tests, benchmarks, re-entry).
init()can panic if a subscriber is already set. Usingtry_init()integrates cleanly withanyhow::Result<()>.- .init(); + .try_init() + .map_err(|e| anyhow::anyhow!(e))?;
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/src/logging.rs(2 hunks)
🔇 Additional comments (2)
server/src/logging.rs (2)
48-53: Gate local-time fmt layer behind LLDAP_LOCAL_TZ_LOG or document UTC→local defaultFile: server/src/logging.rs (lines 48–53)
Confirmed: the code unconditionally installs ChronoLocal::rfc_3339() and therefore ignores the LLDAP_LOCAL_TZ_LOG switch. Either:
- Gate the local-time fmt layer behind LLDAP_LOCAL_TZ_LOG (so local timestamps are opt-in), or
- Keep unconditional local-time but call out the default change (UTC → local) in the PR text and release notes.
Also verify this doesn’t conflict with LLDAP_RAW_LOG (avoid duplicate/reformatted output).
8-10: Compile-time dependency check —chronofeature enabled ontracing-subscriber. server/Cargo.toml declares [dependencies.tracing-subscriber] with features = ["env-filter", "tracing-log", "chrono"] and also includes [dependencies.chrono]; ChronoLocal use in server/src/logging.rs is therefore satisfied.
|
Huh, it's possible that the frontend displays in UTC, I didn't pay that close attention to it. Though I do believe I convert to local time! To be checked. For the logs, try turning on verbose mode, you'll see that user listing returns all the attributes, including the creation time. |
|
Great! While you're at it, if it's a single place and it's not too hard, can we truncate the times to the second, on the web UI? |
|
I believe we can, but its not in a single spot, I have 4 (or 5 see below). create_user.rs#L166 And the technically fifth one could be inserted here user_details_form.rs#L168 to mimic what's done line 201 (consistency) I'm wondering if an extension trait should be done to centralize implementations |
|
One thing that can also be done (but maybe in another commit/PR) is to make nice names for these date fields, they're the only ones in snake_case |
|
If we can have a central place for formatting dates, or even better a type that prints nicely, that would be ideal. And yes, nice names are a nice-to-have, but in a separate PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1296 +/- ##
==========================================
+ Coverage 86.33% 86.38% +0.04%
==========================================
Files 64 64
Lines 12425 12433 +8
==========================================
+ Hits 10727 10740 +13
+ Misses 1698 1693 -5
🚀 New features to boost your workflow:
|
|
sorry if I missed something, are you waiting for my review? |
|
I think we're mostly waiting for QnnOkabayashi/tracing-forest#57 |
Fixes: #1290
Following the discussion we had in #1290, here's a proposition to make lldap logs abide by desired timezone.
This PR introduces a new
LLDAP_LOCAL_TZ_LOGenv variable to make the logs use the defined timezone instead of default UTC.Due to how
tracing_subscriberworks, enablingLLDAP_LOCAL_TZ_LOGgives the same kind of logs as whenLLDAP_RAW_LOGis enabled for simplicity as thewith_timermethod cannot be used without atracing_subscriber::fmt::Layer<S>inner object (doc). But another layer can be made if that behavior isn't desired.This changes uses the
chronofeature fromtracing-subscriberinstead oflocal-timebecause the later only yielded<unknown time>for the timestamp (apparently due to atimecrate issue, see tokio-rs/tracing#2715 for reference.Results:

New
LLDAP_LOCAL_TZ_LOGUnchanged

LLDAP_RAW_LOGUnchanged default behavior
