Comments (6)
Hey Adam,
This is the kind of thing you could do from your appender fn:
{:doc "Like the :standard-out appender, but colors output by logging level"
:min-level nil :enabled? true :async? false :rate-limit nil
:fn (fn [{:keys [error? output level]}] ; Can use any appender args
(binding [*out* (if error? *err* *out*)]
;; TODO: Do a case against `level` to adjust output color
(str-println output)))}
Does that help?
from timbre.
Fantastic!!!! Thanks Peter.
I used the standard-out appender which is perfect for my needs:
(timbre/set-config!
[:appenders :standard-out]
{:doc "Writes to pretty colorized output for log levels > debug"
:min-level :debug
:enabled? true
:async? false
:max-message-per-msecs nil
:fn (fn [{:keys [error? output level]}] ; Can use any appender args
(binding [*out* (if error? *err* *out*)]
(cond
(= level :info) (timbre/str-println (timbre/color-str :green output))
(= level :warn) (timbre/str-println (timbre/color-str :yellow output))
(= level :error) (timbre/str-println (timbre/color-str :red output))
(= level :fatal) (timbre/str-println (timbre/color-str :purple output))
(= level :report) (timbre/str-println (timbre/color-str :blue output))
:else (timbre/str-println output))))})
from timbre.
Great, no problem. Note that you may be able to get that a bit shorter by doing something like:
(if-let [color ({:info :green :warn :yellow :error :red :fatal :purple :report :blue} level)]
(timbre/str-println (timbre/color-str color output))
(timbre/str-println output))
Does that make sense? Enjoy, cheers! :-)
from timbre.
Awesome!! Thanks!
from timbre.
With current config syntax, could be written like this:
(defn config-timbre! []
(let [colors {:info :green, :warn :yellow, :error :red, :fatal :purple, :report :blue}]
(timbre/set-config!
{:level :debug
:output-fn default-output-fn
:appenders
{:color-appender
{:enabled? true
:async? false
:min-level nil
:rate-limit nil
:output-fn :inherit
:fn (fn [{:keys [error? level output-fn] :as data}]
(binding [*out* (if error? *err* *out*)]
(if-let [color (colors level)]
(println (color-str color (output-fn data)))
(println (output-fn data)))))}}})))
from timbre.
@ccfontes what should default-output-fn
be?
Edit: Looks like it's just timbre/default-output-fn
from timbre.
Related Issues (20)
- cljs: JS objects are printed uselessly HOT 2
- Update io.aviso/pretty to 1.2 HOT 1
- Support for `nbb` HOT 2
- Community appenders no longer included in 6.0.0 HOT 2
- 6.0.1. breaks in GraalVM native-image HOT 11
- Add test/s re: GraalVM compatibility HOT 1
- Why are my Timbre timezones different than the system ones? HOT 3
- [shadow-cljs] Invalid :refer, var taoensso.encore/have does not exist HOT 26
- IllegalAccessException when logging internal JDK exception (SunCertPathBuilderException) via `log/error` HOT 13
- shadow-cljs: Advanced build bloated since 6.0.3 HOT 6
- Exception thrown when log arguments have same name, but different separators HOT 2
- Timbre crashing Cider workflow (?) HOT 9
- Using TAOENSSO_TIMBRE_CONFIG_EDN environment variable leads to an execption HOT 4
- Need some help/advice: No debug or info level logging, and duplicated message content HOT 10
- Add console appender opt to control `:raw-console?` HOT 1
- Link to Portal Timbre guide HOT 1
- Latest release uses older com.taoensso/encore; order-dependent if used with e.g. Tufte HOT 2
- API docs link from README results in 404 HOT 3
- Graal optimizations may break uberjar running HOT 5
- Seeing a lot of deprecation warnings in our log HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timbre.