Skip to content

proposal: allow injecting a custom logger (replace hard-coded logrus) #815

@ilCollez

Description

@ilCollez

Summary

compose-go currently logs internally via logrus with no public switch to:

  • silence the output
  • redirect it to another sink
  • integrate with the host application’s structured logger

This proposal asks to make the logger pluggable (e.g. via a WithLogger option) so that consumers can supply any backend (log/slog, Zap, Zerolog, logrus, etc).

I’m volunteering to do the implementation and open a PR once the maintainers are happy with the direction.

What I’m proposing

Notes

  • cli.ProjectOptions and loader.Options are plain structs, so adding a Logger / Handler field is straightforward - the caller just sets it via WithLogger/WithHandler.
  • Many helpers call the global log instance directly. This causes unavoidable side-effects. the cleanest fix would be to pass the logger explicitly as a parameter so every call-site controls its behaviour.
  • If retaining the global instance is required (to avoid large surface changes) we could expose a top-level SetLogger that simply wraps slog.SetDefault, preserving today's pattern while still allowing replacement.

Please let me know if this would be of interest and, if so, what your thoughts on the implementation would be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions