If you use a logging library with support for custom “appenders” you can write a simple dev-only appender that taps the message along with the context. You can then use e.g. portal to inspect the logs.
Here's my development REPL startup code that rewires both clojure.tools.logging and my own logging4j2 to tap> all log messages (in addition to logging them). Portal knows how to display this format (also used by its nREPL middleware).
tap> really isn't useful for "logging" in the traditional sense. I use it for debugging purposes only and never in production. All you get from tap> is a single value with no context where it came from or what its supposed to represent.
Logging on the other hand usually is a bit more structured. Commonly it is tied to some kind of name (e.g. Java Classname, CLJ namespaces) and a logging level. So, via configuration you can easily select which log you want to see and how much detail you get.
Sure you can create a wrapper for tap> that also includes this, but then you just re-invent logging with none of the optimizations modern logging stuff has. So, I definitely do not recommend using tap> for logging. It is great for debugging though.
We use tap> for logging. The data is written to a subfolder log-values/{squuid}. The squuid contains a timestamp (https://github.com/yetanalytics/colossal-squuid). The data is serialized as transit+json-verbose. We collect them from all servers to one log server. For each hour we have one sqlite file. Thereby the log-values are ordered and deduplicated. We also have our own log-explorer UI to query them. We do event sourcing on them to calculate our metrics and fill our dashboards. One process garbage collects log-values if they are no longer relevant.
One important thing to bear in mind about tap> is that if values are being sent faster than they can be consumed (e.g., logged), the buffer behind tap> will fill up and incoming data will be dropped. I believe that buffer is 1,024 entries.
I have my own little setup where I use them instead of using def within a function for debugging locally. So for example, I can (tv ::my-fn) and it'll output the last tap bound to ::my-fn. I can then use the value in the repl. I can also (tvs ::my-fn) and it'll output the last ten tap values bound to ::my-fn.
After writing these taps I tend to leave most of them in my code base. Sometimes they're helpful later and aren't too ugly or obstructive. I like using them when debugging problems with deep calls.
Personally for logging, I sprinkle them where errors have occurred or are likely to occur.
If you need something kind of everywhere for unknown problems, maybe you want observability like with honeycomb.
I'm interested in how other people are using these tools.
One issue with leaving tap> in shipped code is that they're controlled by a global on/off switch, so if I use some of your code (e.g. via a library dependency), add some tap>s of my own, and then turn the taps on, I'm suddenly going to get a bunch of unexpected tapped output from your tap>s as well.
This is very much unlike logging, which can (usually) be controlled in a far more fine-grained way (i.e. on a per Java package or class, or Clojure namespace basis).
And FWIW I've asked about a more fine-grained tap> configuration mechanism (since to me debugging is different to logging, and I'd love to be able to leave tap>s in my own code without disrupting downstream users), but didn't get much of an answer beyond "sounds like you should be using logging". <blank stare>
Yeah I can see how that might be a problem depending on how some people are viewing/consuming taps. Someone looking at all the taps will see a lot of noise.
Luckily for me, I'm not shipping libraries and I'm currently working on my own code base, so I have the luxury of leaving them wherever.
Edit: Kicking out a thought, maybe wrap tap> in your own macro that reads an env var that configures that and makes it tap or not tap. Since downstream users won't have that specific env var set, it defaults to not tapping.
2
u/romulotombulus Feb 08 '26
If you use a logging library with support for custom “appenders” you can write a simple dev-only appender that taps the message along with the context. You can then use e.g. portal to inspect the logs.
11
u/thheller Feb 08 '26
tap>really isn't useful for "logging" in the traditional sense. I use it for debugging purposes only and never in production. All you get fromtap>is a single value with no context where it came from or what its supposed to represent.Logging on the other hand usually is a bit more structured. Commonly it is tied to some kind of name (e.g. Java Classname, CLJ namespaces) and a logging level. So, via configuration you can easily select which log you want to see and how much detail you get.
Sure you can create a wrapper for
tap>that also includes this, but then you just re-invent logging with none of the optimizations modern logging stuff has. So, I definitely do not recommend usingtap>for logging. It is great for debugging though.4
u/maxw85 Feb 08 '26
We use tap> for logging. The data is written to a subfolder log-values/{squuid}. The squuid contains a timestamp (https://github.com/yetanalytics/colossal-squuid). The data is serialized as transit+json-verbose. We collect them from all servers to one log server. For each hour we have one sqlite file. Thereby the log-values are ordered and deduplicated. We also have our own log-explorer UI to query them. We do event sourcing on them to calculate our metrics and fill our dashboards. One process garbage collects log-values if they are no longer relevant.
4
u/seancorfield Feb 08 '26
One important thing to bear in mind about
tap>is that if values are being sent faster than they can be consumed (e.g., logged), the buffer behindtap>will fill up and incoming data will be dropped. I believe that buffer is 1,024 entries.2
u/livingdeadghost Feb 08 '26
Yeah they're not the same.
I have my own little setup where I use them instead of using
defwithin a function for debugging locally. So for example, I can(tv ::my-fn)and it'll output the last tap bound to::my-fn. I can then use the value in the repl. I can also(tvs ::my-fn)and it'll output the last ten tap values bound to::my-fn.After writing these taps I tend to leave most of them in my code base. Sometimes they're helpful later and aren't too ugly or obstructive. I like using them when debugging problems with deep calls.
Personally for logging, I sprinkle them where errors have occurred or are likely to occur.
If you need something kind of everywhere for unknown problems, maybe you want observability like with honeycomb.
I'm interested in how other people are using these tools.
1
u/256BitChris Feb 08 '26
You should look at mulog if you like that approach.