kit icon indicating copy to clipboard operation
kit copied to clipboard

could u support timbre log library

Open vinurs opened this issue 3 years ago • 10 comments

hello, i usually use timebre instead of tools/logging another question: how to log the current file line when use tools.logging

vinurs avatar Dec 09 '22 01:12 vinurs

I think it should be possible to add timbre as an option to the template. It would be a matter of changing the dependency and the config files. And not sure about adding line numbers outside exceptions.

yogthos avatar Dec 09 '22 15:12 yogthos

I also believe it's possible to get clojure.tools.logging to log out to Timbre via https://github.com/ptaoussanis/timbre/blob/master/src/taoensso/timbre/tools/logging.clj#L38

Note: I haven't tried this, so if you do get it working would be worth commenting back since it might be nice to have it as a template option, or module

nikolap avatar Dec 10 '22 17:12 nikolap

@nikolap yes, it can works, but it can not show line number, the reason i want to use timbre is that clojure.tools.logging can not show line number in clj file

2023-04-27 07:40:39 CST vinursdeMacBook-Pro.local INFO [user:?] - clojure.tools.logging can not show line number
2023-04-27 07:40:40 CST vinursdeMacBook-Pro.local INFO [user:86] - timber can show line number

vinurs avatar Apr 26 '23 23:04 vinurs

I'm not familiar with Timbre, however clojure.tools.logging wraps your chosen Java logging provider. e.g. logback is the default one. Perhaps one of these supports your request.

Based off of how Timbre implements it, you could do something like this https://www.reddit.com/r/Clojure/comments/sxwmt9/how_to_log_line_numbers_with_toolslogging/

Hope that helps

nikolap avatar Apr 30 '23 13:04 nikolap

@nikolap thanks, it says just add to your entry point namespace: then ,what's the entry point namespace of luminus and kit-clj , i put it in the app.core, but i found in some namespace it doesn't affect when the server start up

vinurs avatar Apr 30 '23 14:04 vinurs

Yes, the core namespace would be the entry point.

I didn't try the reddit answer extensively, so you may need to tweak it, e.g. to support levels beside INFO. But it certainly worked from the REPL.

However, it won't work for logging produced by non- clojure.tools.logging calls since it's a redef of log/info.

Maybe there's also other ways to enable log numbers in one of the clojure.tools.logging supported logging implementations.

nikolap avatar May 01 '23 12:05 nikolap

i tested , maybe the entry point namespace of kit-clj should be config.clj , now everything works as expect

vinurs avatar May 03 '23 15:05 vinurs

might be worth updating the template to do this by default

yogthos avatar May 03 '23 17:05 yogthos

OK, i will send a pr later, how can i test in my pc?

bb publish-local
+ clojure -T:build install-lib :artifact-id
Unreadable arg: ""
Error while executing task: publish-local

vinurs avatar May 04 '23 01:05 vinurs

you can try running clojure -T:build install-libs instead. For publish-local you have to give it the id of the lib to publish, you can do publish-all-local instead. There are a few examples on the wiki here https://github.com/kit-clj/kit/wiki

yogthos avatar May 04 '23 02:05 yogthos