Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vic1707
Copy link

@vic1707 vic1707 commented Sep 16, 2025

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_LOG env variable to make the logs use the defined timezone instead of default UTC.

Due to how tracing_subscriber works, enabling LLDAP_LOCAL_TZ_LOG gives the same kind of logs as when LLDAP_RAW_LOG is enabled for simplicity as the with_timer method cannot be used without a tracing_subscriber::fmt::Layer<S> inner object (doc). But another layer can be made if that behavior isn't desired.

This changes uses the chrono feature from tracing-subscriber instead of local-time because the later only yielded <unknown time> for the timestamp (apparently due to a time crate issue, see tokio-rs/tracing#2715 for reference.


Results:
New LLDAP_LOCAL_TZ_LOG
image

Unchanged LLDAP_RAW_LOG
image

Unchanged default behavior
image

@coderabbitai
Copy link

coderabbitai bot commented Sep 16, 2025

📝 Walkthrough

Walkthrough

The 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: pub fn init(config: &Configuration) -> anyhow::Result<()>.

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 a String.
  • Please document that LLDAP_LOCAL_TZ_LOG wins over LLDAP_RAW_LOG when 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: use try_init() instead of init()

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 images

Local 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 feature

tracing-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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f04843 and 095c325.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is 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: Enable tracing-subscriber chrono feature — LGTM

Matches the new ChronoLocal usage in logging.rs; feature‑gating is correct and keeps “local-time” disabled as intended.

server/src/logging.rs (2)

9-11: Imports for ChronoLocal and init helpers — LGTM

The import set aligns with the new timer and init path.


48-48: Build registry first, attach a single layer later — LGTM

Clean separation; avoids stacking multiple formatters inadvertently.

Copy link
Member

@nitnelave nitnelave left a 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?

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();
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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

Copy link
Author

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 ?

Copy link
Member

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)

Copy link
Author

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

Copy link
Member

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

Copy link
Author

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 👍

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();
Copy link
Member

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.

Copy link
Author

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 👍

Copy link

@coderabbitai coderabbitai bot left a 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: Prefer try_init() over init() to avoid panics on double initialization (tests, benchmarks, re-entry).

init() can panic if a subscriber is already set. Using try_init() integrates cleanly with anyhow::Result<()>.

-        .init();
+        .try_init()
+        .map_err(|e| anyhow::anyhow!(e))?;
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 095c325 and 8b724e5.

📒 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 default

File: 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 — chrono feature enabled on tracing-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.

@vic1707
Copy link
Author

vic1707 commented Sep 16, 2025

Regarding your concerns about the creation/update dates

image image image

everything looks fine to me, logs in my TZ but the db is still using UTC

frontend is showing UTC tho, wasn't that supposed to be automagically translated or did I misunderstood? 🤔
image

@nitnelave
Copy link
Member

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.

@vic1707
Copy link
Author

vic1707 commented Sep 16, 2025

looks good on verbose mode too 👍
image

Will take a look at the frontend tomorrow (if fix is needed and I find it, maybe I'll include it in the PR as its the same topic)
Will also see for an issue on forest (except if you prefer to do it)
But that'll have to wait tomorrow 😴

@vic1707
Copy link
Author

vic1707 commented Sep 18, 2025

Found a fix for the frontend
image

image

@nitnelave
Copy link
Member

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?

@vic1707
Copy link
Author

vic1707 commented Sep 18, 2025

I believe we can, but its not in a single spot, I have 4 (or 5 see below).

create_user.rs#L166
group_table.rs#L125
user_details_form.rs#L201
user_table.rs#L134

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

@vic1707
Copy link
Author

vic1707 commented Sep 18, 2025

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

@nitnelave
Copy link
Member

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
Copy link

codecov bot commented Sep 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.38%. Comparing base (8f04843) to head (e36c4b4).
⚠️ Report is 3 commits behind head on main.

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     
Files with missing lines Coverage Δ
server/src/logging.rs 84.00% <100.00%> (+1.24%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nitnelave
Copy link
Member

sorry if I missed something, are you waiting for my review?

@vic1707
Copy link
Author

vic1707 commented Oct 4, 2025

I think we're mostly waiting for QnnOkabayashi/tracing-forest#57
As this pr isn't compatible with tracing forest ATM
I believe you can still review it and I can split it to only include the frontend part (so not the CLI logs) if you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] (Docker) Logs not respecting the Timezone

2 participants