Forum How do I...?

Logging to Console Stopped working

fallguy
I'm sure I'm going to say, "Doh," when I get the answer, but here's the question:

I'm trying to debug the TOC javascript in the charms.js file. consoleLog is not writing to the console, EXCEPT for my one test:
consoleLog("hey there");
which I have placed outside of function toc().

The toc function has several lines that SHOULD be printed to the console, such as:

consoleLog("TEXT: ", str);


But these do not write to the console. Only "hey there" appears in the terminal.

I have also put some test writes to the console inside function toc() and function toc_postlayout(toc_args), but they don't appear in the console.

And, yes, the TOC is being written out just fine, so function toc() and function toc_postlayout(toc_args) must be running. I get no errors.

This used to work before. I've seen it! But now...



BTW, another related question: what I'd really like to see is the HTML code rendered by Prince before it's converted to PDF. Using
consoleLog("TEXT: ", str);
is, so far, the best that I can do.

Edited by fallguy

mikeday
Is "console.Log" calling "console.log()"?

You can try this to see the HTML:
console.log(document.documentElement.innerHTML);

It does not emit the root element but will emit all of its descendants.
fallguy
Mike,

I can't say I fully understand your question. Here's what's in the js file:

function consoleLog() {
  if (true) {
     console.log.apply(null,arguments);
  }
}


I'll try your suggestion for viewing the HTML

Edited by fallguy

fallguy
I put
 console.log(document.documentElement.innerHTML);
at the end of my index function. The HTML is written out and I can see the actual HTML code that makes up the Index. Unfortunately, my terminal won't let me scroll back enough to see the TOC. I need to write this to a logfile instead of the console.

I tried
log(document.documentElement.innerHTML);
but it errors. What log file?

I am at a loss as to how to specify it. Using --log=FILE in the command line to run Prince doesn't log that data.
mikeday
It's probably easier to just redirect standard output to a file from the shell:
prince input.html -o out.pdf > log.txt

howcome
The "charms" library is work in progress. Here's the from the most recent version:
var DEBUG=false;

function consoleLog() {
  if (DEBUG) {
     console.log.apply(null,arguments);
  }
}

function debug() {
   DEBUG=true;
   consoleLog("Debugging on");
}


So, to turn on output from "consoleLog", you would first run "debug();". E.g.:

<body onload="debug(); addSidenoteMarks('span','snc')">


Here's the latest charms:

https://css4.pub/2022/charms.js

Edited by howcome

fallguy
RE:
prince input.html -o out.pdf > log.txt


Doesn't work. The PDF is written, and the log.txt file is empty.

Outputting
document.documentElement.innerHTML
to a file strikes me as ideal, but I never was any good at Javascript and that was decades ago. I used to know my way around the UNIX command line pretty OK, but it's been two decades since then. So I need some newbie-style help.

fallguy
howcome,

Thanks for the info. I've downloaded the latest charms.js.
fallguy
Doh! I knew I'd say that.

Mystery solved. I had also created a second javascript file, and modified the index() function to index products in my book (which I am no longer doing). Once I commented out the link to that second javascript file, the consoleLog messages appeared!