I'm using console.log to debug errors while I develop, but it cuts off my stack traces after a handful of lines.
Is it possible to have it not do that?
Is there a better "print to stdout" that I should be using for longer chunks like stack traces?
Edit: Regarding a comment from Ryan Olds, the problem isn't that the stack only includes the most recent "event', but that the string being printed by console.log is truncating after a certain number of characters. It often stops in the middle of a line.
console.error(...) seems to print the full stack message.
Related
When debugging a PHP program with Xdebug, is it possible to set a kind of "conditional breakpoint" not on a specific line, but rather when a certain output is echoed?
This output could be specified by a certain string like id="someid" or by a regexp like id="header(1|2)".
I believe this would be extremely practical when debugging - I know something is wrong with some part of my output, and I want to break the program at the point where it is produced, so I can work up the Call Stack and see what went wrong.
I am using PhpStorm and I would be satisfied by an answer explaining how to do that in this particular IDE. But since I suspect it won't be possible, I ask the question in more generic terms: would Xdebug allow for this?
I am having a problem with Git Bash on Windows. It is always eating the last character on every line which wraps, leading me to sometimes having a repeated letter in my commit messages. Any ideas on how to solve this?
You can see this in the example below, the commit message is correct but not fully displayed.
Never mind, I figured out what the problem was. This only happens when the console overflows, which is why that initial letter g is there. Essentially the program doesn't know that initial g is there, but it still terminates the line after the same amount of characters, so the last letter is swallowed. However, it does not ignore your input, it just doesn't display it.
In our application, we're using Activiti and the issue is that in the log we're getting very large exception stack traces, a couple of hundreds of rows per exception.
Also, the huge stack trace doesn't give additional useful information, so there is no good reason for us to have it.
I'm sure everyone who uses Activiti encountered this issue. How can we reduce the stack traces' size?
Activiti uses slf4j, so one option is to use the logback binding and customize its output using the %ex layout option.
You can find more information in the following link:
Chapter 6: Layouts
The relevant options are copied below:
ex{depth}
exception{depth}
throwable{depth}
ex{depth, evaluator-1, ..., evaluator-n}
exception{depth, evaluator-1, ..., evaluator-n}
throwable{depth, evaluator-1, ..., evaluator-n}
Outputs the stack trace of the exception associated with the logging event, if any. By default the full stack trace will be output.
The throwable conversion word can followed by one of the following options:
short: prints the first line of the stack trace
full: prints the full stack trace
Any integer: prints the given number of lines of the stack trace
Examples
Conversion Pattern Result
%ex mainPackage.foo.bar.TestException: Houston we have a problem
at mainPackage.foo.bar.TestThrower.fire(TestThrower.java:22)
at mainPackage.foo.bar.TestThrower.readyToLaunch(TestThrower.java:17)
at mainPackage.ExceptionLauncher.main(ExceptionLauncher.java:38)
%ex{short} mainPackage.foo.bar.TestException: Houston we have a problem
at mainPackage.foo.bar.TestThrower.fire(TestThrower.java:22)
%ex{full} mainPackage.foo.bar.TestException: Houston we have a problem
at mainPackage.foo.bar.TestThrower.fire(TestThrower.java:22)
at mainPackage.foo.bar.TestThrower.readyToLaunch(TestThrower.java:17)
at mainPackage.ExceptionLauncher.main(ExceptionLauncher.java:38)
%ex{2} mainPackage.foo.bar.TestException: Houston we have a problem
at mainPackage.foo.bar.TestThrower.fire(TestThrower.java:22)
at mainPackage.foo.bar.TestThrower.readyToLaunch(TestThrower.java:17)
I am using the Instruments to profile a very simple program. Here is the result:
result
My question is: why the heaviest back trace are annotated on a very simple line of code? I think that line only needs some ALU instructions to implement. Is this a bug or I missed something?
I see nothing unusual in the screenshot you linked to. The 99x line in your screenshot has nothing to do with the heaviness of the backtrace. It is the line of code where Instruments recorded the most samples. The 99x line is inside a loop. Code inside loops is going to execute more often and have more samples.
I have a tcl script which takes a few minutes to run (the execution time varies based on different configurations).
I want the users to have some kind of an idea of whether it's still executing and how long it would take to complete while the script executes.
Some of the ideas I've had so far:
1) Indicate it using ... which keep increasing with each internal command run or so. But again it doesn't really give a sense of how much more to go for a first time user.
2) Use the revolving slash which I've seen used many places.
3) Have an actual percentage completed output on screen. No idea if this is viable or how to go about it.
Does anyone have any ideas on what could be done so that users of the script understand what's going on and how to do this?
Also if I'm implementing it using ... , how do I get them to print the . on the same line each time. If I use puts to do this in the tcl script the . just gets printed on the next line.
And for the revolving slash, I would need to replace something which was already printed on screen. How can I do this with tcl?
First off, the reason you were having problems printing dots was that Tcl was buffering its output, waiting for a new line. That's often a useful behavior (often enough that it's the default) but it isn't wanted in this case so you turn it off with:
fconfigure stdout -buffering none
(The other buffering options are line and full, which offer progressively higher levels of buffering for improved performance but reduced responsiveness.)
Alternatively, do flush stdout after printing a dot. (Or print the dots to stderr, which is unbuffered by default due to mainly being for error messages.)
Doing a spinner isn't much harder than printing dots. The key trick is to use a carriage return (a non-printable character sometimes visualized as ^M) to move the cursor position back to the start of the line. It's nice to factor the spinner code out into a little procedure:
proc spinner {} {
global spinnerIdx
if {[incr spinnerIdx] > 3} {
set spinnerIdx 0
}
set spinnerChars {/ - \\ |}
puts -nonewline "\r[lindex $spinnerChars $spinnerIdx]"
flush stdout
}
Then all you need to do is call spinner regularly. Easy! (Also, print something over the spinner once you've finished; just do puts "\r$theOrdinaryMessage".)
Going all the way to an actual progress meter is nice, and it builds on these techniques, but it requires that you work out how much processing there is to do and so on. A spinner is much easier to implement! (Especially if you've not yet nailed down how much work there is to do.)
The standard output stream is initially line buffered, so you won't see new output until you write a newline character, call flush or close it (which is automatically done when your script exits). You could turn this buffering off with...
fconfigure stdout -buffering none
...but diagnostics, errors, messages, progress etc should really be written to the stderr stream instead. It has buffering set to none by default so you won't need fconfigure.