Log REPL text to file


#1

Hi all,
Is there a simple command to set up text logging of the REPL output?
Something like MATLAB’s ‘diary’ function: https://www.mathworks.com/help/matlab/ref/diary.html
I always found this useful when running scripts blind on clusters, other wise you end up peppering such scripts with calls to print into a text file.
Cheers
Tim


#2

There are packages like IOLogging.jl for logging different levels to different files, but if you care just about all levels in a single file this example from the docs should work just fine.

Logging all REPL output is not currently possible directly - your best bet is to redirect stdout, but I can’t guarantee that will work.


#3

Thanks, very useful.

I also noticed after a bit more searching (Julia 1.0.2):

In Linux there is a hidden folder:
ls -ld .?*
called “.julia” in my home directory where I have been running Julia from:
vi .julia/logs/repl_history.jl

In Windows its at:
“USERDIR.julia\logs\repl_history.jl”

These appear to contain the whole REPL history.


#4

On Unix systems, you used to able to use the script command to log all input and output in a console. It’s written to a file called typescript by default, and you stop logging using Ctrl-D. However, the big problem is that it records all the ANSI escape sequences as well, making the resulting file virtually unusable for most purposes:

e[0Ke[32me[1mjulia-1.0> e[0me[0m
e[11C[cos(x) for x in range(0, stop=2π, length=200)]
e[58C
e[?2004le[0me[0m200-element Array{Float64,1}:
 1.0               
 0.9995015891261738
 0.9980068533314934
 0.995517282601106 
 0.9920353585932578
 0.9875645521655237
 0.9821093199149804
 0.9756750997357736
 0.9682683053985072
 0.959896320156857 
 0.9505674893877829
 0.9402911122726756
 0.9290774325277306
 0.9169376281927888
 0.9038838004888236
 0.8899289617551803
 0.8750870224785937
 0.859372777426912 
 0.8428018909013506
 0.8253908811219762
 0.8071571037619854
 0.7881187346471924
 0.7682947516379708
 0.7477049157117092
 0.7263697512646394
 ⋮                 
 0.7477049157117087
 0.7682947516379706
 0.7881187346471925
 0.8071571037619851
 0.8253908811219762
 0.8428018909013504
 0.8593727774269119
 0.8750870224785938
 0.8899289617551801
 0.9038838004888236
 0.9169376281927886
 0.9290774325277305
 0.9402911122726754
 0.9505674893877828
 0.959896320156857 
 0.9682683053985071
 0.9756750997357736
 0.9821093199149803
 0.9875645521655236
 0.9920353585932579
 0.9955172826011058
 0.9980068533314933
 0.9995015891261737
 1.0               
e[0K
e[0Ke[32me[1mjulia-1.0> 
e[0K
e[0Ke[32me[1mjulia-1.0> e