Java equivalent of Lisp TRACE
I'm trying to debug some Java code involving complicated mutually recursive functions, and wishing for a debugging facility I have only encountered in Lisp, and wondering if there is a way to implement an equivalent of it.
In Lisp, you can mark a function for tracing, and then each time it is called, a note will be printed to the console along with the argument values. (Okay, this much is easy enough to hack in any language.) Each time it returns, a note will be printed along with the return value. (This is more difficult and more valuable.) Finally, part of what makes it really valuable, recursive calls are marked with indentation. An example from http://clhs.lisp.se/Body/m_tracec.htm if the factorial function FACT is defined recursively:
;; Of course, the format of traced output is implementation-dependent.
(fact 3)
>> 1 Enter FACT 3
>> | 2 Enter FACT 2
>> | 3 Enter FACT 1
>> | | 4 Enter FACT 0
>> | | 4 Exit FACT 1
>> | 3 Exit FACT 1
>> | 2 Exit FACT 2
>> 1 Exit FACT 6
=> 6
Is there a way to do something like this in Java?
java
|
show 4 more comments
I'm trying to debug some Java code involving complicated mutually recursive functions, and wishing for a debugging facility I have only encountered in Lisp, and wondering if there is a way to implement an equivalent of it.
In Lisp, you can mark a function for tracing, and then each time it is called, a note will be printed to the console along with the argument values. (Okay, this much is easy enough to hack in any language.) Each time it returns, a note will be printed along with the return value. (This is more difficult and more valuable.) Finally, part of what makes it really valuable, recursive calls are marked with indentation. An example from http://clhs.lisp.se/Body/m_tracec.htm if the factorial function FACT is defined recursively:
;; Of course, the format of traced output is implementation-dependent.
(fact 3)
>> 1 Enter FACT 3
>> | 2 Enter FACT 2
>> | 3 Enter FACT 1
>> | | 4 Enter FACT 0
>> | | 4 Exit FACT 1
>> | 3 Exit FACT 1
>> | 2 Exit FACT 2
>> 1 Exit FACT 6
=> 6
Is there a way to do something like this in Java?
java
Looks like, you might be looking for someLogging
specific qualities!
– nullpointer
Nov 25 '18 at 4:32
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
1
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
1
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
2
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00
|
show 4 more comments
I'm trying to debug some Java code involving complicated mutually recursive functions, and wishing for a debugging facility I have only encountered in Lisp, and wondering if there is a way to implement an equivalent of it.
In Lisp, you can mark a function for tracing, and then each time it is called, a note will be printed to the console along with the argument values. (Okay, this much is easy enough to hack in any language.) Each time it returns, a note will be printed along with the return value. (This is more difficult and more valuable.) Finally, part of what makes it really valuable, recursive calls are marked with indentation. An example from http://clhs.lisp.se/Body/m_tracec.htm if the factorial function FACT is defined recursively:
;; Of course, the format of traced output is implementation-dependent.
(fact 3)
>> 1 Enter FACT 3
>> | 2 Enter FACT 2
>> | 3 Enter FACT 1
>> | | 4 Enter FACT 0
>> | | 4 Exit FACT 1
>> | 3 Exit FACT 1
>> | 2 Exit FACT 2
>> 1 Exit FACT 6
=> 6
Is there a way to do something like this in Java?
java
I'm trying to debug some Java code involving complicated mutually recursive functions, and wishing for a debugging facility I have only encountered in Lisp, and wondering if there is a way to implement an equivalent of it.
In Lisp, you can mark a function for tracing, and then each time it is called, a note will be printed to the console along with the argument values. (Okay, this much is easy enough to hack in any language.) Each time it returns, a note will be printed along with the return value. (This is more difficult and more valuable.) Finally, part of what makes it really valuable, recursive calls are marked with indentation. An example from http://clhs.lisp.se/Body/m_tracec.htm if the factorial function FACT is defined recursively:
;; Of course, the format of traced output is implementation-dependent.
(fact 3)
>> 1 Enter FACT 3
>> | 2 Enter FACT 2
>> | 3 Enter FACT 1
>> | | 4 Enter FACT 0
>> | | 4 Exit FACT 1
>> | 3 Exit FACT 1
>> | 2 Exit FACT 2
>> 1 Exit FACT 6
=> 6
Is there a way to do something like this in Java?
java
java
asked Nov 25 '18 at 4:30
rwallacerwallace
9,4752173148
9,4752173148
Looks like, you might be looking for someLogging
specific qualities!
– nullpointer
Nov 25 '18 at 4:32
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
1
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
1
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
2
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00
|
show 4 more comments
Looks like, you might be looking for someLogging
specific qualities!
– nullpointer
Nov 25 '18 at 4:32
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
1
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
1
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
2
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00
Looks like, you might be looking for some
Logging
specific qualities!– nullpointer
Nov 25 '18 at 4:32
Looks like, you might be looking for some
Logging
specific qualities!– nullpointer
Nov 25 '18 at 4:32
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
1
1
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
1
1
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
2
2
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464658%2fjava-equivalent-of-lisp-trace%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464658%2fjava-equivalent-of-lisp-trace%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Looks like, you might be looking for some
Logging
specific qualities!– nullpointer
Nov 25 '18 at 4:32
@nullpointer Skimming the documentation on Java logging frameworks, I don't see how they address this use case. What am I missing?
– rwallace
Nov 25 '18 at 4:39
1
Java is not LISP (notably Java objects are "closed") - although there are some AOP frameworks that allow similar. Logging can do this. A profiler is a better bet. Or a debugger.
– Elliott Frisch
Nov 25 '18 at 4:47
1
Nothing I know specifically implements the indented log lines though, and it would be a little tricky to add. It might be possible to add to a log viewer program, if both entry and exit of a function was logged.
– markspace
Nov 25 '18 at 4:50
2
No it's pretty much manually logging every return statement. That's why most of us just use a debugger, or make do without the indentation.
– markspace
Nov 25 '18 at 5:00