Skip to content

[TT-13727] Add RFC3339 compliant option for consistent GW application logs#8157

Merged
shults merged 3 commits into
masterfrom
TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs
May 5, 2026
Merged

[TT-13727] Add RFC3339 compliant option for consistent GW application logs#8157
shults merged 3 commits into
masterfrom
TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs

Conversation

@shults

@shults shults commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

@probelabs

probelabs Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces a configurable logging format to enable RFC3339 compliant timestamps, ensuring more consistent and machine-readable application logs for the Tyk Gateway.

Files Changed Analysis

The changes are centered around the log package, with corresponding updates to configuration and service initialization to adopt the new system:

  • log/log.go: Introduces a new Format type with options: text (new default), json, and legacy. The text and json formats use RFC3339 timestamps. A new SetupFormatter function centralizes logger configuration and, critically, configures the global logrus.StandardLogger() to ensure logs from third-party dependencies also adhere to the selected format.
  • log/log_test.go: Unit tests are significantly expanded to validate the behavior of SetupFormatter for all new formats, ensuring both the main Tyk logger and the global logrus logger are configured correctly.
  • config/config.go: The LogFormat field is updated to use the new logger.Format type, and comments are revised to reflect the new options (text, json, legacy) and the new default (text).
  • gateway/server.go: The gateway's startup process is modified to call the new tyklog.SetupFormatter function, replacing the previous direct formatter assignment.
  • certs/manager.go: Instances of logrus.New() are replaced with tyklog.Get() to ensure the globally configured logger is used, respecting the application-wide format.
  • cli/linter/schema.json: The JSON schema for the linter is updated to include the new log_format enum values: text and legacy.

Architecture & Impact Assessment

  • What this PR accomplishes
    The PR allows users to select a log output format via the log_format configuration option. The primary goal is to shift from a legacy timestamp to the widely adopted RFC3339 standard, improving interoperability with external logging systems while maintaining backward compatibility through the legacy option.

  • Key technical changes introduced

    • A new log_format configuration option is available in tyk.conf and via the TYK_GW_LOGFORMAT environment variable.
    • The default log timestamp format is now RFC3339 (text format). This is a behavioral change for existing installations that do not have this value set.
    • The new log.SetupFormatter function configures both the main Tyk logger and the global logrus.StandardLogger(). This is a significant architectural improvement that enforces a consistent log format across the entire application and its dependencies.
  • Affected system components

    • Logging Subsystem: The log package is directly modified to support multiple formatter types.
    • Gateway Configuration & Startup: The gateway's startup sequence in gateway/server.go is updated to use the new logger setup mechanism.
    • All Gateway Logs: Because the change affects the global logrus logger, any component or third-party library that uses it will now produce logs in the format specified in the Tyk configuration, leading to consistent output across the entire application.

Logging Initialization Flow

graph TD
    A[Gateway Startup] --> B{Read `log_format` from config};
    B --> C["log.SetupFormatter(format)"];
    C --> D{Switch on format};
    D --|text or default|--> E[Create TextFormatter w/ RFC3339];
    D --|json|--> F[Create JSONFormatter w/ RFC3339];
    D --|legacy|--> G[Create TextFormatter w/ legacy timestamp];
    subgraph "Apply Formatter"
        E --> H[Set Tyk logger AND global logrus logger];
        F --> H;
        G --> I[Set ONLY Tyk logger];
    end
    H --> J[Consistent RFC3339 Logs];
    I --> K[Legacy Formatted Logs];
Loading

Scope Discovery & Context Expansion

The impact of this change is application-wide. By modifying the global logrus.StandardLogger(), the PR ensures that any module or dependency using the standard logrus instance will now produce logs in the format defined by the Tyk configuration. This is a significant improvement for operational consistency.

The default value for log_format is now "text". This means that existing users who upgrade will see their log timestamp format change unless they explicitly set log_format: "legacy" in their configuration file. This is a minor breaking change for log parsing but a positive step towards standardization that should be highlighted in release notes.

Metadata
  • Review Effort: 2 / 5
  • Primary Label: enhancement

Powered by Visor from Probelabs

Last updated: 2026-05-05T12:58:38.426Z | Triggered by: pr_updated | Commit: f4dde3e

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Security Check Passed

No security issues found – changes LGTM.

\n\n

Architecture Issues (1)

Severity Location Issue
🟡 Warning gateway/server.go:1587
The application's logging is configured in two separate places: once at package initialization time in `log/log.go` (reading from environment variables), and again here in `gateway.initSystem()` (reading from the config file). This conditional reconfiguration, controlled by checking `os.Getenv("TYK_LOGFORMAT")`, creates a non-obvious configuration precedence where environment variables will always override the config file. While this PR did not introduce this pattern, it increases its impact because the new `SetupFormatter` function modifies the global `logrus` logger state, making the initialization order more critical. The initial configuration from `init()` now has wider-reaching effects than before.
💡 SuggestionRefactor the configuration initialization to occur at a single point. The `log` package should not self-configure from the environment in an `init()` block. Instead, it should be explicitly configured by a single call from the application's startup routine (e.g., in `main` or `initSystem`) after all configuration sources (files, env vars, flags) have been loaded and reconciled. This would make the initialization flow linear, predictable, and easier to understand.

✅ Performance Check Passed

No performance issues found – changes LGTM.

✅ Quality Check Passed

No quality issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-05-05T12:58:28.430Z | Triggered by: pr_updated | Commit: f4dde3e

💡 TIP: You can chat with Visor using /visor ask <your question>

@shults
shults force-pushed the TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs branch from 73ae2ea to bd7720f Compare April 28, 2026 12:36
@shults
shults force-pushed the TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs branch from bd7720f to 87f0b35 Compare April 29, 2026 09:34

@MFCaballero MFCaballero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shults

shults commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

HI @shults changes look good but can we adjust the config comments https://github.com/TykTechnologies/tyk/blob/master/config/config.go#L1240 to account for these new options as this is automated for docs? We might also need to update https://github.com/TykTechnologies/tyk/blob/master/cli/linter/schema.json#L965

Hi @MFCaballero. Thank you for your response. It makes sense. Would you mind reviewing the changes?

@shults
shults force-pushed the TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs branch from 23c1911 to f4dde3e Compare May 5, 2026 12:56
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

🚨 Jira Linter Failed

Commit: f4dde3e
Failed at: 2026-05-05 12:57:20 UTC

The Jira linter failed to validate your PR. Please check the error details below:

🔍 Click to view error details
failed to get Jira issue: failed to fetch Jira issue TT-13727: Issue does not exist or you do not have permission to see it.: request failed. Please analyze the request body for more details. Status code: 404

Next Steps

  • Ensure your branch name contains a valid Jira ticket ID (e.g., ABC-123)
  • Verify your PR title matches the branch's Jira ticket ID
  • Check that the Jira ticket exists and is accessible

This comment will be automatically deleted once the linter passes.

@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
81.8% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@shults
shults enabled auto-merge (squash) May 5, 2026 14:01
@shults
shults merged commit 432bcba into master May 5, 2026
53 of 55 checks passed
@shults
shults deleted the TT-13727-add-rfc-3339-compliant-option-for-consistent-gw-application-logs branch May 5, 2026 14:25
@shults

shults commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

/release to release-5.8

@shults

shults commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

/release to release-5.13

@probelabs

probelabs Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Cherry-pick encountered conflicts. A draft PR was created: #8178

@probelabs

probelabs Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

✅ Cherry-pick successful. A PR was created: #8179

shults added a commit that referenced this pull request May 5, 2026
… logs (#8157)

<!-- Provide a general summary of your changes in the Title above -->

<!-- Describe your changes in detail -->

<!-- This project only accepts pull requests related to open issues. -->
<!-- If suggesting a new feature or change, please discuss it in an
issue first. -->
<!-- If fixing a bug, there should be an issue describing it with steps
to reproduce. -->
<!-- OSS: Please link to the issue here. Tyk: please create/link the
JIRA ticket. -->

<!-- Why is this change required? What problem does it solve? -->

<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests -->
<!-- you ran to see how your change affects other areas of the code,
etc. -->
<!-- This information is helpful for reviewers and QA. -->

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

(cherry picked from commit 432bcba)
shults added a commit that referenced this pull request May 5, 2026
…consistent GW application logs (#8157) (#8179)

[TT-13727] Add RFC3339 compliant option for consistent GW application
logs (#8157)

<!-- Provide a general summary of your changes in the Title above -->

## Description

<!-- Describe your changes in detail -->

## Related Issue

<!-- This project only accepts pull requests related to open issues. -->
<!-- If suggesting a new feature or change, please discuss it in an
issue first. -->
<!-- If fixing a bug, there should be an issue describing it with steps
to reproduce. -->
<!-- OSS: Please link to the issue here. Tyk: please create/link the
JIRA ticket. -->

## Motivation and Context

<!-- Why is this change required? What problem does it solve? -->

## How This Has Been Tested

<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests -->
<!-- you ran to see how your change affects other areas of the code,
etc. -->
<!-- This information is helpful for reviewers and QA. -->

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

[TT-13727]:
https://tyktech.atlassian.net/browse/TT-13727?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Co-authored-by: Yaroslav Kotsur <[email protected]>
shults added a commit that referenced this pull request May 6, 2026
…onsistent GW application logs (#8157) (#8178)

Cherry-pick of `432bcba341df25f1f35292f07075008d65c65a98` from `master`
to `release-5.8` requires manual resolution.

  **Conflicts detected:** 3
   - gateway/server.go
  
  Tips:
- Check out this branch locally and run: `git cherry-pick -x
432bcba`
- Resolve conflicts (including submodules if any), then push back to
this branch.
  
Original commit:
432bcba

---------

Co-authored-by: Tyk Bot <[email protected]>
Co-authored-by: Yaroslav Kotsur <[email protected]>
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.

3 participants