clojure - 当参数是大映射时跟踪函数

标签 clojure trace

当我跟踪一个函数时,如果其中一个参数是包含大量元素的嵌套映射,则跟踪会充满困惑。这是一个典型的例子:

TRACE t36705: (get-value {:nodeclass :simple, :nodeid :simple25, :dock {:constan
t-dock {:name :constant-dock, :value 22, :dockclass {:name :constant-dock, :link
-policy {:lp-committed? #object[fargish.links$fn__5756 0x407956a5 "fargish.links
$fn__5756@407956a5"], :lp-reciprocate-no-commitment #object[clojure.core$constan
tly$fn__4614 0x69497a36 "clojure.core$constantly$fn__4614@69497a36"], :lp-recipr
ocate-commitment #object[clojure.core$constantly$fn__4614 0x30ee413a "clojure.co
re$constantly$fn__4614@30ee413a"], :lp-can-boost-to #object[fargish.links$fn__57
58 0x5df17e60 "fargish.links$fn__5758@5df17e60"], :lp-official-partners #object[
fargish.links$fn__5760 0x3df2f4ab "fargish.links$fn__5760@3df2f4ab"], :lp-normal
ize-after-add #object[clojure.core$constantly$fn__4614 0x386cc1c4 "clojure.core$
constantly$fn__4614@386cc1c4"], :lp-reduce-to-uncommitted #object[fargish.links$
fn__5765 0x7bd4f212 "fargish.links$fn__5765@7bd4f212"], :lp-committed-to #object
[fargish.links$fn__5767 0x5c3cc103 "fargish.links$fn__5767@5c3cc103"], :lp-boost
 #object[fargish.links$fn__5771 0x423e35f0 "fargish.links$fn__5771@423e35f0"]}, 
:maker #object[fargish.spec_test$eval36501$__GT_Dock_constant_dock__36515 0x19cc
229b "fargish.spec_test$eval36501$__GT_Dock_constant_dock__36515@19cc229b"]}}, :
function-dock {:name :function-dock, :value #fargish.spec.Vfunc{:args (constant-
dock), :f #object[fargish.spec_test$fn__36544 0x135647d3 "fargish.spec_test$fn__
36544@135647d3"]}, :dockclass {:name :function-dock, :link-policy {:lp-committed
? #object[fargish.links$fn__5756 0x407956a5 "fargish.links$fn__5756@407956a5"], 
:lp-reciprocate-no-commitment #object[clojure.core$constantly$fn__4614 0x69497a3
6 "clojure.core$constantly$fn__4614@69497a36"], :lp-reciprocate-commitment #obje
ct[clojure.core$constantly$fn__4614 0x30ee413a "clojure.core$constantly$fn__4614
@30ee413a"], :lp-can-boost-to #object[fargish.links$fn__5758 0x5df17e60 "fargish
.links$fn__5758@5df17e60"], :lp-official-partners #object[fargish.links$fn__5760
 0x3df2f4ab "fargish.links$fn__5760@3df2f4ab"], :lp-normalize-after-add #object[
clojure.core$constantly$fn__4614 0x386cc1c4 "clojure.core$constantly$fn__4614@38
6cc1c4"], :lp-reduce-to-uncommitted #object[fargish.links$fn__5765 0x7bd4f212 "f
argish.links$fn__5765@7bd4f212"], :lp-committed-to #object[fargish.links$fn__576
7 0x5c3cc103 "fargish.links$fn__5767@5c3cc103"], :lp-boost #object[fargish.links
$fn__5771 0x423e35f0 "fargish.links$fn__5771@423e35f0"]}, :maker #object[fargish
.spec_test$eval36523$__GT_Dock_function_dock__36537 0x34584446 "fargish.spec_tes
t$eval36523$__GT_Dock_function_dock__36537@34584446"]}}}} constant-dock)
TRACE t36705: => nil

有什么技巧可以让这些痕迹打印出来时不那么困惑?我不期望痕迹非常容易阅读,但必须有比这更好的方法。

最佳答案

不幸的是,clojure.tools.trace 不允许自定义跟踪日志的输出。我不确定您是否可以在运行之间修改源代码,或者您需要一种机制来插入正在运行的系统,在该系统中您无法修改函数实现。

从您的评论来看,您似乎可以修改要跟踪的函数。根据您仅记录函数参数内容的子集的要求,我将切换到普通日志记录(使用 println 或使用某些日志记录框架)并添加显式日志记录表达式以仅记录相关数据。

例如:

(defn some-function
  [a b]
  (println "some-function" {:a (select-keys a [:x :y]) :b (select-keys b [:x :z])})
  (comment your function body))

这并不像将 defn 更改为 deftrace 那么容易,但可以按照您想要的任何方式进行自定义。

关于clojure - 当参数是大映射时跟踪函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36722077/

相关文章:

java - java中switch语句没有赋值会发生什么?

python-3.x - 使用 pytest 运行 trace.py

C# 条件日志记录/跟踪

clojure - Clj-http 异常 : ExceptionInfo clj-http: status 415 clj-http. client/wrap-exceptions/fn--1863 (client.clj:196)

clojure - 如何在 Light Table 中自动智能缩进文件

clojure - 使用 clojure.data.xml 从 Clojure 发出 XML。

java - 如何在 Clojure 中实现 Java 接口(interface)

map - Clojure 基于优先级逻辑从 map 中提取值(value)

debugging - 如何为 Prolog 使用有效的调试器/跟踪

.net - 使用 Ent-Lib 拨号跟踪的意外后果,没有错误记录