简体   繁体   中英

Filtering substrate logs

When running a substrate node, how can I filter log lines according to a word or pattern present in a line of the logs?

I've tried running:

RUST_LOG=runtime=debug cargo run -- --dev | grep 'INFO'

However that still gives me all the lines of the output, for instance:

2021-03-03 12:01:18.292  DEBUG main runtime: Called should_end_session    
2021-03-03 12:01:18.292  DEBUG main runtime: Cannot fetch slot number    
2021-03-03 12:01:18.684   INFO main sc_service::builder: 📦 Highest known block at #41    
2021-03-03 12:01:18.688   INFO tokio-runtime-worker substrate_prometheus_endpoint::known_os: 〽️ Prometheus server started at 127.0.0.1:9615    
2021-03-03 12:01:18.708   INFO                 main parity_ws: Listening for new connections on 127.0.0.1:9944.    
2021-03-03 12:01:18.963   INFO ThreadId(33) parity_ws::io: Accepted a new tcp connection from 127.0.0.1:62079.    
2021-03-03 12:01:19.131   WARN          event.loop0 sc_rpc_api::errors: Unknown error: Client(UnknownBlock("header not found in db: 0x6eb1…618b"))    
2021-03-03 12:01:19.132   WARN          event.loop0 sc_rpc_api::errors: Unknown error: Client(UnknownBlock("header not found in db: 0x6eb1…618b"))    
2021-03-03 12:01:20.124   INFO ThreadId(33) parity_ws::io: Accepted a new tcp connection from 127.0.0.1:62080.    
2021-03-03 12:01:21.433  DEBUG tokio-runtime-worker runtime: Called should_end_session    
2021-03-03 12:01:21.433  DEBUG tokio-runtime-worker runtime: Cannot fetch slot number    
2021-03-03 12:01:21.536   INFO tokio-runtime-worker sc_basic_authorship::basic_authorship: 🙌 Starting consensus session on top of parent 0xa246d8880f1a820bb2275b78e728471c38c3406271d12b3f852fa717a5338c95  

One simple solution: if you redirect stdout and stderr into a file (the &> command) you could filter through this using any method you like.

You may also want to use the tee command to view the output in terminal and to a file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM