kit-clj / kit

Lightweight, modular framework for scalable web development in Clojure
https://kit-clj.github.io/
MIT License
476 stars 44 forks source link

could u support timbre log library #83

Open vinurs opened 1 year ago

vinurs commented 1 year ago

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

yogthos commented 1 year ago

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.

nikolap commented 1 year ago

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

vinurs commented 1 year ago

@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
nikolap commented 1 year ago

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

vinurs commented 1 year ago

@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

nikolap commented 1 year ago

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.

vinurs commented 1 year ago

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

yogthos commented 1 year ago

might be worth updating the template to do this by default

vinurs commented 1 year ago

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
yogthos commented 1 year ago

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