Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
88c1f42
Initial commit
cecton Oct 7, 2020
95762f1
WIP
cecton Oct 9, 2020
685c122
WIP
cecton Oct 14, 2020
fea1d0c
WIP
cecton Oct 14, 2020
f0d5964
WIP
cecton Oct 15, 2020
a55ccf0
WIP
cecton Oct 15, 2020
ad7dbd5
CLEANUP
cecton Oct 15, 2020
c8e0841
Add notes to original source code
cecton Oct 15, 2020
dc2f401
CLEANUP
cecton Oct 15, 2020
34106dd
CLEANUP
cecton Oct 15, 2020
76f2d43
WIP
cecton Oct 15, 2020
0c278a8
WIP
cecton Oct 16, 2020
8257480
WIP
cecton Oct 16, 2020
47f7d3f
CLEANUP
cecton Oct 16, 2020
efb9b82
WIP
cecton Oct 16, 2020
346eaf1
Some doc
cecton Oct 16, 2020
9055ec2
Test with trybuild
cecton Oct 16, 2020
d46d87b
Revert "Test with trybuild" (issue with trybuild atm)
cecton Oct 16, 2020
2401a7c
Apply suggestions
cecton Oct 16, 2020
364b1b9
Merge commit ec1834646c3f81305dd01cc85d003d7be76daebf (no conflict)
cecton Oct 16, 2020
25970af
Rename derive to proc-macro
cecton Oct 16, 2020
8480619
Remove "prefix" feature from informant
cecton Oct 16, 2020
b14c3f8
Blocking task should use SpawnHandle::spawn_blocking
cecton Oct 16, 2020
499ade7
Improve doc as suggested
cecton Oct 16, 2020
aea5b53
Fixes
cecton Oct 16, 2020
0c83890
Apply suggestion
cecton Oct 16, 2020
2e6b613
Update client/cli/proc-macro/src/lib.rs
cecton Oct 21, 2020
3f61450
More suggestions
cecton Oct 21, 2020
a554480
CLEANUP
cecton Oct 21, 2020
58a7284
Improve error message
cecton Oct 21, 2020
de4678f
CLEANUP
cecton Oct 21, 2020
c101a09
Fix async issue
cecton Oct 21, 2020
35ae152
CLEANUP
cecton Oct 21, 2020
fb4c7bb
CLEANUP
cecton Oct 21, 2020
2238794
Add test
cecton Oct 21, 2020
c4e0039
fix doc test
cecton Oct 21, 2020
1a72fc5
Merge commit c2469ebdfbb9d051f892c7b896e835d78d60838d (no conflict)
cecton Oct 21, 2020
2752062
Update client/cli/src/logging.rs
cecton Oct 21, 2020
208bbe2
Update client/basic-authorship/src/basic_authorship.rs
cecton Oct 21, 2020
243dd6c
Update client/basic-authorship/src/basic_authorship.rs
cecton Oct 21, 2020
929bd1e
Apply suggestions
cecton Oct 21, 2020
f12a3f7
Suggestions
cecton Oct 21, 2020
b9d7723
Clarify doc
cecton Oct 21, 2020
f141b73
WIP
cecton Oct 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some doc
  • Loading branch information
cecton committed Oct 16, 2020
commit 346eaf1babfbc96c12d433d37156fbd0c7b7812a
74 changes: 74 additions & 0 deletions client/cli/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,80 @@ use proc_macro_crate::crate_name;
use quote::quote;
use syn::{Error, Expr, Ident, ItemFn};

/// Macro that inserts a span with the node name at the beginning of the function. This prefix all
/// the log lines with `[<name>]` (after the timestamp).
///
/// # Implementation notes
///
/// If there are multiple spans with a node name, only the latest will be shown.
///
/// # Example with a literal
///
/// ```ignore
/// Builds a new service for a light client.
/// #[sc_cli::substrate_cli_node_name("light")]
/// pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
/// let (client, backend, keystore, mut task_manager, on_demand) =
/// sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
///
/// ...
/// }
/// ```
///
/// Will produce logs that look like this:
///
/// ```text
/// 2020-10-16 08:03:14 Substrate Node
/// 2020-10-16 08:03:14 ✌️ version 2.0.0-47f7d3f2e-x86_64-linux-gnu
/// 2020-10-16 08:03:14 ❤️ by Anonymous, 2017-2020
/// 2020-10-16 08:03:14 📋 Chain specification: Local Testnet
/// 2020-10-16 08:03:14 🏷 Node name: nice-glove-1401
/// 2020-10-16 08:03:14 👤 Role: LIGHT
/// 2020-10-16 08:03:14 💾 Database: RocksDb at /tmp/substrate95w2Dk/chains/local_testnet/db
/// 2020-10-16 08:03:14 ⛓ Native runtime: node-template-1 (node-template-1.tx1.au1)
/// 2020-10-16 08:03:14 [light] 🔨 Initializing Genesis block/state (state: 0x121d…8e36, header-hash: 0x24ef…8ff6)
/// 2020-10-16 08:03:14 [light] Loading GRANDPA authorities from genesis on what appears to be first startup.
/// 2020-10-16 08:03:15 [light] ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
/// 2020-10-16 08:03:15 [light] Using default protocol ID "sup" because none is configured in the chain specs
/// 2020-10-16 08:03:15 [light] 🏷 Local node identity is: 12D3KooWHX4rkWT6a6N55Km7ZnvenGdShSKPkzJ3yj9DU5nqDtWR
/// 2020-10-16 08:03:15 [light] 📦 Highest known block at #0
/// 2020-10-16 08:03:15 [light] 〽️ Prometheus server started at 127.0.0.1:9615
/// 2020-10-16 08:03:15 [light] Listening for new connections on 127.0.0.1:9944.
/// ```
///
/// # Example using the actual node name
///
/// ```ignore
/// Builds a new service for a light client.
/// #[sc_cli::substrate_cli_node_name(config.network.node_name.as_str())]
/// pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
/// let (client, backend, keystore, mut task_manager, on_demand) =
/// sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
///
/// ...
/// }
/// ```
///
/// Will produce logs that look like this:
///
/// ```text
/// 2020-10-16 08:12:57 Substrate Node
/// 2020-10-16 08:12:57 ✌️ version 2.0.0-efb9b822a-x86_64-linux-gnu
/// 2020-10-16 08:12:57 ❤️ by Anonymous, 2017-2020
/// 2020-10-16 08:12:57 📋 Chain specification: Local Testnet
/// 2020-10-16 08:12:57 🏷 Node name: open-harbor-1619
/// 2020-10-16 08:12:57 👤 Role: LIGHT
/// 2020-10-16 08:12:57 💾 Database: RocksDb at /tmp/substrate9T9Mtb/chains/local_testnet/db
/// 2020-10-16 08:12:57 ⛓ Native runtime: node-template-1 (node-template-1.tx1.au1)
/// 2020-10-16 08:12:58 [open-harbor-1619] 🔨 Initializing Genesis block/state (state: 0x121d…8e36, header-hash: 0x24ef…8ff6)
/// 2020-10-16 08:12:58 [open-harbor-1619] Loading GRANDPA authorities from genesis on what appears to be first startup.
/// 2020-10-16 08:12:58 [open-harbor-1619] ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
/// 2020-10-16 08:12:58 [open-harbor-1619] Using default protocol ID "sup" because none is configured in the chain specs
/// 2020-10-16 08:12:58 [open-harbor-1619] 🏷 Local node identity is: 12D3KooWRzmYC8QTK1Pm8Cfvid3skTS4Hn54jc4AUtje8Rqbfgtp
/// 2020-10-16 08:12:58 [open-harbor-1619] 📦 Highest known block at #0
/// 2020-10-16 08:12:58 [open-harbor-1619] 〽️ Prometheus server started at 127.0.0.1:9615
/// 2020-10-16 08:12:58 [open-harbor-1619] Listening for new connections on 127.0.0.1:9944.
/// ```
#[proc_macro_attribute]
pub fn substrate_cli_node_name(arg: TokenStream, item: TokenStream) -> TokenStream {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this name, as this doesn't reflect what its doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will think of it 🤔 (do you have already an idea for a better name?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substrate_cli_span_prefix?

let item_fn = syn::parse_macro_input!(item as ItemFn);
Expand Down