Skip to content

[TT-7099] [Customer FR] Send info and debug messages to stdout not stderr - #1024

Open
shults wants to merge 1 commit into
masterfrom
TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr
Open

[TT-7099] [Customer FR] Send info and debug messages to stdout not stderr#1024
shults wants to merge 1 commit into
masterfrom
TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr

Conversation

@shults

@shults shults commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

Logger injection. TykPump is being used as a library in the GW.
As a developer, I need the ability to inject a logger instance, rather than use the global one.

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)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

Ticket Details

TT-7099
Status In Dev
Summary Configurable sinks for application logs [Gateway]

Generated at: 2026-07-28 20:23:59

@shults
shults force-pushed the TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr branch from 16f8bf2 to 8abc894 Compare June 2, 2026 11:35
@probelabs

probelabs Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This pull request refactors the NewAnalyticsSerializer function to enable logger injection, addressing a need for consumers who use Tyk Pump as a library, such as the Tyk Gateway. By replacing the reliance on a global logger instance with a functional options pattern, this change allows host applications to provide their own logrus.Logger instance. This facilitates unified and consistent logging across different systems.

The implementation introduces a new WithLogger option for the NewAnalyticsSerializer constructor. The change is fully backward-compatible; if no custom logger is provided, the serializer defaults to the original global logger, ensuring no disruption to existing functionality.

Files Changed Analysis

  • serializer/serializer.go: The core logic change is here. The NewAnalyticsSerializer function was updated to accept functional options, and the package-level global logger was removed in favor of a logger configured on a per-instance basis.
  • serializer/serializer_test.go: New unit tests have been added in Test_WithLogger to validate that a logger provided via the new WithLogger option is correctly used by the serializer.

Architecture & Impact Assessment

  • What this PR accomplishes: It decouples the analytics serializer from a global logger, which enhances modularity and simplifies the integration of tyk-pump as a library into other applications that have their own logging infrastructure.
  • Key technical changes introduced: The functional options pattern has been implemented for dependency injection, which is a best practice in Go for providing optional configuration and avoiding breaking API changes.
  • Affected system components: The primary impact is on the instantiation of AnalyticsSerializer. While the change is intended for external consumers like the Tyk Gateway, any part of the system that creates a serializer is technically affected, though the default behavior remains unchanged.
graph TD
    subgraph "Before"
        A[Application] --> B(NewAnalyticsSerializer)
        B --> C[Global Logger]
    end
    subgraph "After"
        D[Host Application] --|WithLogger(customLogger)|--> E(NewAnalyticsSerializer)
        E --> F{Use customLogger if provided, else Default Logger}
    end
Loading

Scope Discovery & Context Expansion

  • The change is localized to the serializer package. While the PR itself doesn't modify the call sites within the tyk-pump binary, the primary consumer is likely external (e.g., Tyk Gateway), where this new functionality will be leveraged.
  • This change is foundational and enables other systems to better control logging behavior. The misleading PR title, "Send info and debug messages to stdout not stderr," likely refers to a downstream goal that this logger injection capability will unblock for a customer, rather than what this specific PR implements directly.
Metadata
  • Review Effort: 2 / 5
  • Primary Label: enhancement

Powered by Visor from Probelabs

Last updated: 2026-07-28T20:25:15.146Z | Triggered by: pr_updated | Commit: 958a99e

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

@probelabs

probelabs Bot commented Jun 2, 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 serializer/serializer.go:42-44
The `case MSGP_SERIALIZER` with `fallthrough` is redundant. The `default` case already provides the desired behavior for `MSGP_SERIALIZER` and any other unspecified serializer type. This can be simplified by removing the explicit case for `MSGP_SERIALIZER`.
💡 SuggestionRemove the `case MSGP_SERIALIZER:` and `fallthrough` to simplify the switch statement, as the `default` case handles this logic.
🔧 Suggested Fix
    default:
        opt.logger.Debugf("Using serializer %v for analytics \n", MSGP_SERIALIZER)
        return &MsgpSerializer{}

✅ Performance Check Passed

No performance issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-07-28T20:25:00.370Z | Triggered by: pr_updated | Commit: 958a99e

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

@shults shults changed the title [TT07099] [Customer FR] Send info and debug messages to stdout not stderr [TT-7099] [Customer FR] Send info and debug messages to stdout not stderr Jun 10, 2026
@shults
shults force-pushed the TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr branch from 8abc894 to 3dfa82e Compare June 12, 2026 08:45
@shults
shults force-pushed the TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr branch from 3dfa82e to 09dd3b6 Compare June 23, 2026 09:51
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarQube Cloud

@shults
shults force-pushed the TT-7099-customer-fr-send-info-and-debug-messages-to-stdout-not-stderr branch from 09dd3b6 to 958a99e Compare July 28, 2026 20:23
@github-actions

Copy link
Copy Markdown
Contributor

🎯 Recommended Merge Targets

Based on JIRA ticket TT-7099: Configurable sinks for application logs [Gateway]


📋 Workflow

  1. Merge this PR to master first

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarQube Cloud

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.

2 participants