[Ethereum] How to write transaction logs into a text file in geth

eventsgo-ethereumlogs

I have made a contract which generates a public event on blockchain that will notify client about a transaction.
To listen to the event I have written following snippet in geth console:

var event = token.CoinTransfer({}, '', function(error, result){
  if (!error)
    console.log("Coin transfer: " + result.args.amount + " tokens were sent. Balances now are as following: \n Sender:\t" + result.args.sender + " \t" + token.coinBalanceOf.call(result.args.sender) + " tokens \n Receiver:\t" + result.args.receiver + " \t" + token.coinBalanceOf.call(result.args.receiver) + " tokens" )
});

Now instead of console.log() I want these transaction to be stored in a text file TransactionHistory.txt. How can we do this? Is there a better way than listening to event, to maintain transaction logs?

Best Answer

Probably is best that you exec the script from a file anyway

 geth --exec 'loadScript("/tmp/test.js")' attach 

Then you can direct the output, for example in Linux and Mac:

 geth --exec 'loadScript("/tmp/checkbalances.js")' attach > log.txt
Related Topic