Comments (3)
Hello, I would not encourage you to use with-redefs
for that (or anything), but have you read the customization section from the docs? It's really meant for this sort of use case. You can also pass the inline :sc/spy-ep-pre-eval-logger-fn
and :sc/spy-ep-post-eval-logger-fn
opts.
When I want to catch on Exceptions only, I usually do it by wrapping the exception in a try/catch and spying inside the catch
clause.
Other options are:
- using a
brk
, then exiting with an error - spying at random:
(when (zero? (rand-int 100)) (sc.api/spy))
People have very different opinions regarding such workflow optimizations; this is why I recommend writing your own spy...
wrappers in your project's utility namespace.
from scope-capture.
Update: I traced the source of the logging and tried redefining these functions with no-ops:
sc.api.logging/log-spy-ep-pre-eval
sc.api.logging/log-spy-ep-post-eval
That alone reduced the execution time to 51ms, so it turned out the huge majority of the overhead was due to all the println
logging.
There doesn't look to be a simple way of switching this logging behaviour off - perhaps a dynamic var of some sort like sc.api/*log-spy-execution*
or a separate spying macro?
Here's what I'm using for the time being:
(defmacro spy' [& args]
`(with-redefs [sc.api.logging/log-spy-ep-pre-eval (fn [~'ep])
sc.api.logging/log-spy-ep-post-eval (fn [~'ep])]
(sc/spy ~@args)))
Let me know and I'd be willing to contribute a PR :)
from scope-capture.
Thanks for all the pointers! That's what I get for digging through the source but not the documentation
Being able to conditionally (spy)
anywhere is pretty nice, I had the wrong impression that it had to always be wrapped around an expression.
Here's my modified macro from above, for anyone interested:
(def spysl-opts
{:sc/spy-ep-post-eval-logger (fn [ep])
:sc/spy-ep-pre-eval-logger (fn [ep])})
(defmacro spysl
"Spy silently - do not print anything at execution points."
([] (sc.api/spy-emit spysl-opts nil &env &form))
([expr] (sc.api/spy-emit spysl-opts expr &env &form))
([opts expr] (sc.api/spy-emit (merge spysl-opts opts) expr &env &form)))
from scope-capture.
Related Issues (20)
- Scope-capture doesn't play nice when used in core.async's go-block HOT 4
- Add automated tests for (self-hosted) CLJS
- Spy logging interferes with compiled JS in CLJS HOT 9
- Disable prn of captured values at execution time HOT 4
- Alternate spy with less noisy defaults
- option for only spying downstream of some caller
- CompilerException java.lang.ClassNotFoundException: sc.api.from compiling:(sc/impl.cljc:171:9) HOT 2
- Working with shadow-cljs? HOT 2
- Capturing values in thread first or thread last statements HOT 2
- Cool discovery: you can nest `letsc`! HOT 2
- Request: alias for "most recent ID" HOT 3
- Support for naming code sites
- Error in tutorial HOT 1
- Non intrusive support for naming code sites: multi methods
- Use in production? HOT 4
- Shortcut to use the `last-ep-id` in `letsc`
- doucmnet possibility to inject into `core.ns` ?
- Not getting local-bindings as expected.
- How should i get the execution point and code site without using logs?
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 scope-capture.