How do I log to stdout or stderr from an Erlang common test suite? - erlang

I'm using common_test and just want to log values to stdout or stderr.
How????
I've tried:
ct:comment
ct:log
io:format
The state of the art seems to be manually combing through html files. But I'm on a server and I don't care about anything except my log line, I only want stdout. And I never want to look at an HTML file when writing tests, so advice on how to avoid that generally would be really helpful.

You should use ct:print or ct:pal (print and log), I'd recommend using the later, though.
(You can always use erlang:display, which is a low-level access to stdout)
Keep in mind that if you use Rebar3 with the default configuration and ct values. ct:print is only shown with --verbose, whereas, ct:pal is only shown if the test fails.

Related

Extract lines from Kubernetes log

I'm new to kubernetes and am still trying to extract log from a few lines and write it, if anyone can help me what commands i should execute.
If the pod is named bino, and i wanted to extract the lines corresponding to the error unable-to-access-website, and then write them to a certain location, say John/Doe/bino. How would i do this is there a easy command?
I tried using kubectl log bino, but it just dumps all the output on the terminal, if i wanted to write certain parts how can i do it? Thanks!
Or if anyone has played around in katacoda i would appreciate a link to a similar example.
You can use grep in linux to fetch the relevant log messages you want:
kubectl log bino | grep "error unable-to-access-website" >> John/Doe/Bino/log.txt
Hope this helps.
If you are not that familiar with grep and regular expressions in general, then you can use the Retrospective Log Analyzer https://retrospective.centeractive.com/tutorial_monitorcontainer.html which will do the heavy regex work for you.
It makes extracting certain parts of the logs much easier, you can extract parts from log files and from container logs of Kubernetes and Docker without having to write complex regular expressions.

how can I get the procedure's log which is run on a harness instance?

As the https://github.com/neo4j-examples/neo4j-procedure-template/blob/3.3/src/main/java/example/FullTextIndex.java shows, the example shows a public Log log; field but barely use it.
In my case, I use this field to print some log but find it in nowhere, so where is it? And what's more, can I just print the log on the junit console?
Use log.info("message") in your code and go to Neo4j/Logs is in Logs folder neo4j.log file.
Answer by myself:
According to the source code, the logs for harness is saved in /tmp/xxxx/neo4j.log
And the neo4j.log is hard code, I cannot find a way to redirect it to the standard system.out.
Or I can just use System.out.print() in my code, but since this part is not a test code, use System.out.print() only for harness test is a bad idea.
I'll come back if I found a way to redirect the neo4j to System.out

Bypassing --More-- in Rails Console

I would like to analyze all the posts created by users of my Rails App, which is hosted on Heroku. In the console, I created a variable that contains every word ever posted on the site, which accounts for hundreds of thousands of words. I'd like to export these words from the console to do analysis elsewhere.
I've read from this post that using Tee enables you to get a copy of the output of your console:
How to export a Ruby Array from my Heroku console into CSV?
The problem is that if I try to print all the words, the console always shows '--More--', at which point I press the enter key to reveal more of the text. As you can imagine, for hundreds of thousands of words, it would be impractical for me to keep pressing enter to reveal the entirety of the text. How can I bypass this?
heroku run console | tee output.txt
If you're using tee-trick above, you can just type q to exit your terminal pager program (I assume it's more) since tee writes simultaneously into the standard out (that's why you're seeing all the output and more automatically starts to page it) and to the file you gave it on the argument (output.txt in the case above).
Since you don't need/want to view all the output, just quit more and do what you want with the file.
Have you tried a plain old unix shell redirect?
heroku run console > output.txt
Probably is is better to write a rake task to output your data, so that is not mixed with other things that happen in the console. When you just use stdout (for example puts), then something like this should work:
heroku rake db:postexport > output.txt

How can stdout be redirected in iOS?

I am importing some legacy code into an iOS app that uses stdout for some diagnostic output. Of course, iOS does not like you to write to stdout at all, and I need to get that output anyway. I would like to redirect this output to a file, then use the same legacy code again, redirecting the output to a different file. Does anyone know of a way to do this?
I've tried the simplistic
freopen(p, "w", stderr);
This does work--but only once. After using this call, all output to stdout is forever redirected. That's OK, but subsequent calls to redirect the output to a new location cause system instability that eventually leads to a crash. (I have tested this running from XCode, but not directly from a rebooted iPad. I don't know for sure the instability persists if not running in XCode using DEBUG mode.)
I've also tried the method in this post. This works, too, but does not return the system to its original state, and again, only works once. (If you try this at home, include Apple's <unisys.h> instead of <io.h>, and leave the _ off of calls like _dup and _dup2.)
I really don't want to have to go through the code and replace all uses of printf, etc to use an explicit file. In addition to being time consuming, error prone, and ugly, the code is open source. I don't expect the original authors would appreciate my changes, and I don't really want to have to reintegrate the changes each time the original project is updated.
Thoughts?

Applescript: print first or other specific pages

How can you instruct an application or the printer to only print the first page, a page range or just odd or even pages of a file? I attempt this with the help of the Preview app, which looks promising:
set theFile to "[file-path/file]""
tell application "Preview"
activate
print theFile with properties {target printer:"Printer", ending page:1} without «class pdlg»
--these properties isn't available for the printer app, here just limiting amount of printed pages
quit
end tell
But with this I'm bitten by the sandboxd process that tells me the file can't be opened for printing and I get a deny file-read-data result in the log.
In the CUPS suggestion by adamh I encounter issues with umlauts and have other execution issues as well, possibly also because of sandbox rules. The code works from the command line, but not when called in automated fashion.
I tried to look up useful examples of the print command in a reference, in my books and tried searching the online Apple references, but I can't seem to find many examples fitting to the present day situation with sandbox, if any.
You could script printing by command line tool lp & lpr.
These talk to CUPS, Common Unix Printing System
To target pages / ranges:
lp -o page-ranges=2-4 "my_great_document.pdf"
To call it from applescript use do shell script
e.g,
do shell script "lp -o page-ranges=2-4 'my_great_document.pdf'"
For more ideas see: http://www.cups.org/documentation.php/options.html

Resources