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

Question about def-loggers #21

Closed
weejulius opened this issue Jul 22, 2013 · 5 comments
Closed

Question about def-loggers #21

weejulius opened this issue Jul 22, 2013 · 5 comments

Comments

@weejulius
Copy link

Hi,

I am not sure if it is appropriate to put question here, please close it if it not.

The question is what is the reason to make the def-loggers private, I want to use timbre as logging tool, but I would like to wrap it so it is flexible for me.

I make a poor workaround by copying def-loggers and so on into the logging.clj file in my personal project.

Thanks

Julius

@ptaoussanis
Copy link
Member

Hi Julius,

I am not sure if it is appropriate to put question here, please close it if it not.

Sure, this is the right place to ask :-)

I make a poor workaround by copying def-loggers and so on into the logging.clj file in my personal project.

Can you explain what you want to do here exactly? Do you want to change something in def-logger or ordered-levels?

If you just want the logging macros (info, infof, error, errorf, etc.) to be available to your namespace, I would usually recommend doing that with something like:

(ns my-app (:require [taoensso.timbre :as timbre
                      :refer (trace debug info warn error fatal spy with-log-level)]))

But maybe I misunderstand you?

@weejulius
Copy link
Author

:), I just want the source codes refer to those macros under my namespace (:require [logging :as log]) like t_logging.clj instead of
[taoensso.timbre :as timbre
:refer (trace debug info warn error fatal spy with-log-level)]

@ptaoussanis
Copy link
Member

Okay, I think I understand. I think using def-loggers in your own ns is maybe a bad idea. It would be better to use :require and :refer.

If :refer (trace debug info warn error fatal spy with-log-level) is too long, you can write a fn like this:

(defn require-timbre []
  (require '[taoensso.timbre :as timbre :refer (trace debug info warn error fatal spy with-log-level)])

Then you can call (require-timbre) under your ns form. I will think about adding this to Timbre officially.

Another idea: you can require log or logf which lets you choose a logging level yourself, like (log :info "Log this").

Does that help?

@ptaoussanis
Copy link
Member

Okay, I have added refer-timbre to v2.4.0.

@weejulius
Copy link
Author

It does help, Thanks a lot. Actually what I did is not about to save the time to press the long require statement, I want to abstract the logging interface, so that the code will not be changed a lot after switching the logging implementation.

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

No branches or pull requests

2 participants