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

Print warnings to STDERR to avoid polluting STDOUT #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmatysiak
Copy link

Printing warnings to STDOUT pollutes the output of any program that uses STDOUT. This patch makes sure warnings are directed to STDERR.

@mebble
Copy link

mebble commented Sep 25, 2022

Could we also have the ability to suppress warnings? I have an app that logs to stderr and I don't want environ polluting those logs. I was thinking an API that looks something like this:

(env :env-key {:warnings false})

I'm new to clojure and don't know how to work with defonce so I'm unable to raise my own PR

@dmatysiak
Copy link
Author

IMO, ideally, we shouldn't be logging this way in the first place (or using environment variables to enable or disable warnings, for that matter). If warnings are a must, a compromise might be to add a dynamic var to enable warnings (and one to override the file descriptor):

(def ^:dynamic *warnings?* false)
(def ^:dynamic *warnings-out* *err*)

(defn- printerr [& more]
  (when *warnings?*
      (apply println more)))

after which you can optionally enable these messages, e.g.:

(binding [environ/*warnings* true]
    ...your naughty code...)

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.

None yet

2 participants