Eos: print("\n") seems some wrong.when comes one print("\n"),the latter doesn't work.

Created on 13 Sep 2018  路  9Comments  路  Source: EOSIO/eos

void testbr(){
        print("test1\n");
        print("test2\n");
}

When call the contranct action,it only print test1.

Support

Most helpful comment

An odd decision, especially given how many hours you steal from new developers who wonder whether their smart contract has the desired effect - or any effect at all.

I will note that EOS's own documentation recommends: _The main method used to debug smart contract is Caveman Debugging, where we utilize the printing functionality to inspect the value of a variable and check the flow of the contract. Printing in smart contract can be done through the Print API (C and C++). The C++ API is the wrapper for C API, so most often we will just use the C++ API._

All 9 comments

can you provide the output?

I've reproduced the same situation. I've an action called test structured in this way:

void test(account_name user) {
        print("print1\n");
        print("print2\n");
        print( "Hello, ", name{user} );
    }

I've created an account test and called the action cleos push action test test '["a"]' -p test. In the console with cleos i see

executed transaction: a5851c60516db247a9e73c64348db847875f05cbcca8ceb765443fc5f008ca2a  104 bytes  4284 us
#          test <= test::test                   {"user":"a"}
>> print1
warning: transaction executed locally, but may not be confirmed by the network yet    ]

so only the first print is printed. BTW, if a look at the console with nodeos running, i see all the data printed (i've the flag --contracts-console set in nodeos):

2018-09-14T08:35:10.960 thread-0   apply_context.cpp:28          print_debug          ]
[(test,test)->test]: CONSOLE OUTPUT BEGIN =====================
print1
print2
Hello, a
[(test,test)->test]: CONSOLE OUTPUT END   =====================

cleos only prints the first line. Add --verbose to your cleos for more output.

Even if i modify the command in cleos --verbose push action test test '["a"]' -p test the output is still the same. I think because the verbose flag works only if there is an error, as written in the helper: -v,--verbose output verbose actions on error

Yep, forgot that. Use --json to get full output.

Using cleos push action test test '["a"]' -p test --json i can get the result in json format "console": "print1\nprint2\nHello, a". So there is no way at the moment to print more than one line in cleos without print the whole json right?

Correct. cleos only prints the first line. We could add an option I suppose to print all lines. But at some point it is better to just output json and let the user format as desired.

An odd decision, especially given how many hours you steal from new developers who wonder whether their smart contract has the desired effect - or any effect at all.

I will note that EOS's own documentation recommends: _The main method used to debug smart contract is Caveman Debugging, where we utilize the printing functionality to inspect the value of a variable and check the flow of the contract. Printing in smart contract can be done through the Print API (C and C++). The C++ API is the wrapper for C API, so most often we will just use the C++ API._

For the benefit of any readers who may stumble on this issue, here's how I was able to work around this:

cleos push action -j ..... > output.json
jq -r '.processed.action_traces[].console' output.json 

using the jq utility.
If you're debugging an notify action, then it would be:

jq -r '.processed.action_traces[].inline_traces[].console' output.json
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ResponsiveWebApps picture ResponsiveWebApps  路  3Comments

christola picture christola  路  3Comments

hoopslb picture hoopslb  路  3Comments

williamleecn picture williamleecn  路  3Comments

toonsevrin picture toonsevrin  路  3Comments