aergoio / aergo

aergo blockchain kernel
http://docs.aergo.io
MIT License
214 stars 45 forks source link

brick should allow bypassing of quoting of log lines #117

Open aspiers opened 4 years ago

aspiers commented 4 years ago

When debugging via brick, it can be extremely helpful to add logging of multiline statements to the smart contract. For example maybe we want to see a stack trace at the current execution point:

system.print(debug.traceback())

But currently this results in something like this very long line:

INF "stack traceback:\u000a\u0009[string \"0cca71fcf76698693693c6edc703ea42c82494bfafa1b6a14100aabaa7a1afb08f\"]:773: in function 'f'\u000a\u0009[string \"0cca71fcf76698693693c6edc703ea42c82494bfafa1b6a14100aabaa7a1afb08f\"]:49: in function 'cancel'\u000a\u0009[string \"0cca71fcf76698693693c6edc703ea42c82494bfafa1b6a14100aabaa7a1afb08f\"]:794: in function <[string \"0cca71fcf76698693693c6edc703ea42c82494bfafa1b6a14100aabaa7a1afb08f\"]:787>\u000a\u0009[C]: at ?" Contract SystemPrint=AmhUpxjiT8KhQXX6N3QmZMwZJ4FoDzbwFogxnBNNF4SHs1btauXx module=contract 

Even if #113 is fixed, the fact that many characters are escaped makes this very hard to understand. The biggest problem is that newlines are rendered as \u000a, so it's really difficult to visually parse the stacktrace. But it would also be helpful if other characters like " were also not escaped.

I understand that this change would break the convention of one logging event per line, and maybe on a production blockchain that is unacceptable. But in brick when the emphasis is on testing and debugging it is more helpful. So I suggest either we change this for brick, or at least add a new option to brick which disables quoting.

aspiers commented 4 years ago

Here is a very quick and ugly workaround which strips some of the quoting:

brick foo.brick -v -w 2>&1 | perl -pe 's/\\"/"/g; s/\\u00(\w\w)/chr hex $1/ge'