Skip to content
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

Duplicate logs when using coloredlogs #310

Open
2 tasks done
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Open
2 tasks done

Duplicate logs when using coloredlogs #310

kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Labels
archive question Further information is requested

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

An issue by mhamann at 2020-02-11 05:34:31+00:00
Original URL: zalando-incubator/kopf#310
 

Question

I'm using the coloredlogs library to format my log output. When it's enabled, I end up getting duplicate logs: one line from kopf's logging handler and one from the coloredlogs handler I configured.

Is there a way to get kopf to piggyback on my existing coloredlogs setup? (I imagine this would work for any existing Python logging setup, not just mine.)

Checklist

Keywords

  • duplicate logs
  • coloredlogs

Commented by nolar at 2020-02-13 16:56:26+00:00
 

Kopf injects its own logger in kopf.configure() based on --verbose, --debug, or --quiet CLI options. See the source code.

The easiest way would be to define your @kopf.on.startup() handler, and tweak the handlers of the root logger (logging.getLogger().handlers[:] = []). But few initial lines will be logged in the original setup anyway (before the startup handler is invoked).


Another way would be not to use kopf run CLI command, but define your own CLI entry point, and run the operator task yourselves. It should be as simple as this code, except that the options should be defined somehow by yourselves:

import kopf

@kopf.on.event(...)
def fn(...): ...

def main():
    # setup your logging here
    kopf.run(
        standalone=...,
        namespace=...,
        priority=...,
        peering_name=...,
        liveness_endpoint=...,
    )

Also see: embedding the operators if you want something even more advanced.


And yet another way would be adding a CLI option to Kopf itself, handled somewhere around these lines: https://github.com/nolar/kopf/blob/0.25/kopf/cli.py#L24-L34. And then, (re-)configuring your own logging on the module level statements or in @kopf.on.startup() handler.

E.g. --logging=none — which would also match with future --logging=json, --logging=plain, --logging=full (default), and other formats (see #44). With --logging=none, it can skip the configuration at all, and use the default Python logging, or whatever is configured otherwise.

See this diff for ideas (it was my experimentation branch — just ignore the part with JSON, look only at PLAIN/FULL formats).

@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] Duplicate logs when using coloredlogs Aug 19, 2020
@kopf-archiver kopf-archiver bot added the question Further information is requested label Aug 19, 2020
@kopf-archiver kopf-archiver bot reopened this Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive question Further information is requested
Projects
None yet
Development

No branches or pull requests

0 participants