Although I am using Mathematica 9 notebook usually, I am interested in the logging input and output in a text-based interface of Wolfram Language.
I found a package of SessionLog.m in Programming Mathematica written by Roman Maeder.
$cat SessionLog.m
(* ::Package:: *)
BeginPackage["ProgrammingInMathematica`SessionLog`"]
OpenLog::usage = "OpenLog[filename, opts..] starts logging all input and output to filename."
CloseLog::usage="CloseLog[] closes the logfile opened by OpenLog[]."
Begin["`Private`"]
logfile=""
OpenLog[ filename_String, opts___?OptionQ] := (
logfile = OpenWrite[filename, opts];
If[ logfile === $Failed, Return[logfile] ];
AppendTo[$Echo, logfile];
AppendTo[$Output, logfile];
logfile
)
CloseLog[] := (
$Echo = Complement[$Echo, {logfile}];
$Output = Complement[$Output, {logfile}];
Close[logfile]
)
End[ ]
Protect[ OpenLog, CloseLog ]
EndPackage[]
My trial is the following.
pi@raspberrypi ~/workmath $ sudo wolfram
Wolfram Language (Raspberry Pi Pilot Release)
Copyright 1988-2013 Wolfram Research
Information & help: wolfram.com/raspi
In[1]:= << SessionLog.m
In[2]:= OpenLog["session.log"]
Out[2]= OutputStream[session.log, 56]
In[3]:= Expand[ (x+y)^3 ]
3 2 2 3
Out[3]= x + 3 x y + 3 x y + y
In[4]:= CloseLog[]
Out[4]= session.log
In[5]:= Quit[]
pi@raspberrypi ~/workmath $ cat session.log
Out[2]= OutputStream["session.log", 56]
Expand[ (x+y)^3 ]Out[3]= x^3 + 3*x^2*y + 3*x*y^2 + y^3
CloseLog[]
I want to make another format which is written in the book.
Out[2]= OutputStream["session.log", 56]
Expand[ (x+y)^3 ]
Out[3]= x^3 + 3*x^2*y + 3*x*y^2 + y^3
CloseLog[]
Would you please give me a suggestion how to solve this problem ?
Yoshihiro Sato