当参数是大地图时跟踪函数 [英] Tracing functions when the arguments are big maps

查看:134
本文介绍了当参数是大地图时跟踪函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跟踪一个函数时,如果其中一个参数是一个具有大量元素的嵌套映射,那么这个跟踪被填充了杂乱。这里有一个典型的例子:

When I trace a function, if one of the arguments is a nested map with a lot of elements, the trace is filled with clutter. Here's a typical example:

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

什么是设置东西的技术,这些痕迹打印出来没有这么多杂乱?我不认为跟踪是超级容易阅读,但是有一个比这更好的方法。

What's a technique for setting things up so these traces print out without so much clutter? I don't expect traces to be super-easy to read, but there has to be a better way than this.

推荐答案

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

Unfortunately, clojure.tools.trace doesn't allow customizing the output of trace logs. I wasn't sure if you could modify your source code between runs or you needed a mechanism to plugin into a running system where you cannot modify function implementation.

看来你可以修改一个你想要跟踪的函数。基于你只需要记录函数参数内容的一个子集的要求,我将切换到普通的日志记录(使用 println 或一些日志框架),并添加显式记录表达式到日志相关数据。

From your comment it seems you can modify a function you want to trace. Based on your requirement to log only a subset of function's arguments content I would switch to ordinary logging (either with println or with some logging framework) and add explicit logging expressions to log only relevant data.

例如:

(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 ,但可以按照您想要的方式进行自定义。

It's not that easy as changing defn to deftrace but can be customized any way you want.

这篇关于当参数是大地图时跟踪函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆