I currently have some code that's outputing A LOT of console.log lines. as of now I've been running it like this: node index.js > output.txt however, this isn't enough anymore since after a few hours the file becomes WAY too big to open in most editors.
Whats a better way to handle constant log creation in node? Is there a way to create a new log (with like output<TIMESTAMP>.txt) that would be created once the previous file reaches X size?
Pass your logs to a script rather than a file and handle the stream within your script for log rotation.
A good starting point is https://unix.stackexchange.com/questions/231486/how-to-implement-logrotate-in-shell-script
Related
I'm not the best at explaining this stuff but here I go.
I have a program that uses "tesseract.js" to read an image every second or so.
10% of images have an "Empty page!!" error message, but I don't need or want this error message flooding my otherwise useful error log. I want to remove it from the source code, however, it isn't fired from the easily readable js code...
I assume it is fired from the wasmBinaryFile section, which (if I understand correctly) is a wasm binary compiled version of the original C++ (Tesseract 4.1.1)
In C++ Tesseract, the error message is fired from \src\textord\colfind.cpp line 366. If I knew where the equivalent section of the binary code was, I assume that I could remove it.
I know that decompiling wasm to C++ won't necessarily be understandable, but if I did it, would I be able to compare it to the source code for Tesseract and either find the section I need to remove or be able to recompile it for use again?
If so, would someone be able to point me towards a good software to do this?
You don't need to revers engineer that code, tesseract is open source, has a github page and you can look at the source code here :
https://github.com/tesseract-ocr/tesseract/blob/main/src/textord/colfind.cpp.
It also means you can use git to get a local copy, modify and compile it. Probably you can even find a way to change tprintf
Is there a way to run a program (for example: tcpdump) and every time it shows something through the console, from nodejs capture it and return the result to print in an html? no need to save it, keep it in real time.
My idea is that a program can be executed and while it is running and showing things in the console, they can be sent to the html where you can progressively see all the results of the program's execution.
Thanks for help.
I think using socket io is a good solution,
check there get started tutorial
No need to do anything like "capturing output" in Node.js. You can use the heredoc available in almost every shell. The heredoc, in the most basic sense, redirects the output of a command to a file. In your example, if you use tcpdump, here's what you'd do:
$ tcpdump [options] >> file.html
The >> heredoc operator appends to a file(create if doesn't exist). This means if you already have some content in file.html, the content will still be there, and the output will be appended to the end of the file.
The > heredoc writes to a file(also, create if doesn't exist). So, if you have some content in file.html, that will be overwritten with the new content.
is there a way how to debug source maps in chrome? At least to see where is what mapped?
My problem is that I am remapping ts generated file (using source-maps), for whatever reason, does not matter. When I remap them and use console.log or console.error the console correctly shows the line where the console.log or console.error was executed and I can even navigate to the line in the original ts source file. But when I try to set a break point in the .js file on the same line where the console.log is located the break point is set incorrectly to "previous" line (or other file, if there is no any statement in the .ts file)
So the question is, is there a way to tell to chrome to show me mapped relations for js and ts files? If no, is there any other tool, ideally friendly, where I can click on statement and see were is it mapped to? I am lazy to write one, especially in this case I am not sure what I am doing wrong.
Thanks
EDIT:
In between I have found this:
http://sokra.github.io/source-map-visualization/#
and this:
https://github.com/danvk/source-map-explorer
I could not find anything because I was asking google in a wrong way.
EDIT2:
My bundled and remapped files seems to be ok.
It seems to be a bug in chrome debuger itself. Because when I place a break point directly to the typescript file it stops correctly.
So it seems to me the chrome incorrectly maps only breakpoints set in the original (bundled) js file what is actually bundle of compiled typescipt files accompanied with remapped .js.map files to the .js.map bundle.
Is there a way to copy all the commands i have written, or to give it some range. Or at least print them out together so i can copy them.
I was trying out jquery selectors in console, after half hour of dealing with very messy dom structure i finally got what i wanted now to transfer that i have to back in history and copy paste every single command. It'd be nice if could log all i have writen, or like last 30 commands etc.
I think it should be possible, as i have seen pretty other advanced abilities of chrome console.
This answer appears to address your question.
Enable logging from the command line using the flags:
--enable-logging --v=1
This logs everything Chrome does internally, but it also logs all the
console.log() messages as well. The log file is called
chrome_debug.log and is located in the User Data Directory.
Filter the log file you get for lines with 'CONSOLE(\d+)'.
via Save the console.log in Chrome to a file
More here on logging. The Chromium Projects: How to enable logging
Say I have the following Node program, a machine that goes "Ping!":
var machine = require('fs').createWriteStream('machine.log', {
flags : 'a',
encoding : 'utf8',
mode : 0644
});
setInterval(function () {
var message = 'Ping!';
console.log(message);
machine.write(message + '\n');
}, 1000);
Every second, it will print a message to the console and also append it to a log file (which it will create at startup if needed). It all works great.
But now, if I delete the machine.log file while the process is running, it will continue humming along happily, but the writes will no longer succeed because the file is gone. But it looks like the writes fail silently, meaning that I would need to explicitly check for this condition. I've searched the Stream docs but can't seem to find an obvious event that is emitted when this type of thing occurs. The return value of write() is also not useful.
How can I detect when a file I'm writing to is deleted, so I can try to reopen or recreate the file? This is a CentOS box, if that's relevant.
The writes actually do not fail.
When you delete a file that is open in another program you are deleting a named link to that file's inode. The program that has it open still points to that inode. It will happily keep writing to it, actually writing to disk. Only now you don't have a way to look it at, because you deleted the named reference to it. (If there were other references, e.g. hard links, you would still be able to!).
That's why programs that expect their log files to "disappear" (b/c of logrotate, say) usually support a signal (usually SIGHUP and sometimes SIGUSR1) that tells them to close their file (at which point it is really gone, because now there are no links to it anywhere) and re-create it.
You should consider something like that as well.