Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
CLEANUP
Forked at: d67fc4c
Parent branch: origin/master
  • Loading branch information
cecton committed Oct 15, 2020
commit ad7dbd58d5f9364b5e944dc16c02bcbabe08a4e5
11 changes: 2 additions & 9 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ pub use runner::*;
use sc_service::{Configuration, TaskExecutor};
pub use sc_service::{ChainSpec, Role};
pub use sp_version::RuntimeVersion;
use std::fmt;
use std::io::Write;
pub use structopt;
use structopt::{
clap::{self, AppSettings},
StructOpt,
};
use tracing::{Event, Subscriber, Id, span::{self, Attributes}, Level};
use tracing_subscriber::{
filter::Directive, fmt::{time::{SystemTime, ChronoLocal, FormatTime}, FormatEvent, FmtContext, FormatFields}, layer::{SubscriberExt, Context}, FmtSubscriber, Layer, registry::LookupSpan,
filter::Directive, fmt::time::ChronoLocal, layer::SubscriberExt, FmtSubscriber, Layer,
};
use std::fmt::Write as OtherWrite;
use ansi_term::{Colour, Style};
use std::iter;
use tracing_log::NormalizeEvent;

/// Substrate client CLI
///
Expand Down Expand Up @@ -316,10 +310,9 @@ pub fn init_logger(
ansi: enable_color,
display_target: !simple,
display_level: !simple,
display_thread_id: false,
display_thread_name: !simple,
})
.finish().with(logging::MyLayer);
.finish().with(logging::NodeNameLayer);

if let Some(tracing_targets) = tracing_targets {
let profiling = sc_tracing::ProfilingLayer::new(tracing_receiver, &tracing_targets);
Expand Down
127 changes: 72 additions & 55 deletions client/cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
use std::fmt;
use tracing::{Event, Subscriber, Id, span::{self, Attributes}, Level};
use tracing_subscriber::{
filter::Directive, fmt::{time::{SystemTime, ChronoLocal, FormatTime}, FormatEvent, FmtContext, FormatFields}, layer::{SubscriberExt, Context}, FmtSubscriber, Layer, registry::LookupSpan,
};
use std::fmt::Write as OtherWrite;
// This file is part of Substrate.

// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use ansi_term::{Colour, Style};
use std::fmt;
use std::fmt::Write as _;
use std::iter;
use tracing::{
span::{self, Attributes},
Event, Id, Level, Subscriber,
};
use tracing_log::NormalizeEvent;
use tracing_subscriber::{
fmt::{
time::{FormatTime, SystemTime},
FmtContext, FormatEvent, FormatFields,
},
layer::Context,
registry::LookupSpan,
Layer,
};

pub(crate) struct EventFormat<T = SystemTime> {
pub(crate) timer: T,
pub(crate) ansi: bool,
pub(crate) display_target: bool,
pub(crate) display_level: bool,
pub(crate) display_thread_id: bool,
pub(crate) display_thread_name: bool,
}

Expand All @@ -23,15 +49,18 @@ where
N: for<'a> FormatFields<'a> + 'static,
T: FormatTime,
{
fn format_event(&self, ctx: &FmtContext<S, N>, writer: &mut dyn fmt::Write, event: &Event) -> fmt::Result {
fn format_event(
&self,
ctx: &FmtContext<S, N>,
writer: &mut dyn fmt::Write,
event: &Event,
) -> fmt::Result {
let normalized_meta = event.normalized_metadata();
let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata());
time::write(&self.timer, writer, self.ansi)?;

if self.display_level {
let fmt_level = {
FmtLevel::new(meta.level(), self.ansi)
};
let fmt_level = { FmtLevel::new(meta.level(), self.ansi) };
write!(writer, "{} ", fmt_level)?;
}

Expand All @@ -42,62 +71,52 @@ where
write!(writer, "{} ", FmtThreadName::new(name))?;
}
// fall-back to thread id when name is absent and ids are not enabled
None if !self.display_thread_id => {
None => {
write!(writer, "{:0>2?} ", current_thread.id())?;
}
_ => {}
}
}

if self.display_thread_id {
write!(writer, "{:0>2?} ", std::thread::current().id())?;
}

// Custom code to display node name
ctx.visit_spans::<fmt::Error, _>(|span| {
let exts = span.extensions();
if let Some(node_name) = exts.get::<MyFormattedFields>() {
if let Some(node_name) = exts.get::<NodeName>() {
write!(writer, "{}", node_name.as_str())
} else {
Ok(())
}
}).unwrap();
})
.unwrap();

let fmt_ctx = {
FmtCtx::new(&ctx, event.parent(), self.ansi)
};
let fmt_ctx = { FmtCtx::new(&ctx, event.parent(), self.ansi) };
write!(writer, "{}", fmt_ctx)?;
if self.display_target {
write!(writer, "{}:", meta.target())?;
}
ctx.format_fields(writer, event)?;
let span = ctx.lookup_current();
if let Some(ref id) = span.map(|x| x.id()) {
if let Some(span) = ctx.metadata(id) {
write!(writer, "{}", span.fields()).unwrap_or(());
}
}
writeln!(writer)
}
}

pub(crate) struct MyLayer;
pub(crate) struct NodeNameLayer;

impl<S> Layer<S> for MyLayer
impl<S> Layer<S> for NodeNameLayer
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let span = ctx.span(id).expect("new_span has been called for this span; qed");
let span = ctx
.span(id)
.expect("new_span has been called for this span; qed");
let mut extensions = span.extensions_mut();

if extensions.get_mut::<MyFormattedFields>().is_none() {
if extensions.get_mut::<NodeName>().is_none() {
let mut s = String::new();
let mut v = StringVisitor { string: &mut s };
attrs.record(&mut v);

if !s.is_empty() {
let fmt_fields = MyFormattedFields(s);
let fmt_fields = NodeName(s);
extensions.insert(fmt_fields);
}
}
Expand All @@ -123,9 +142,9 @@ impl<'a> tracing::field::Visit for StringVisitor<'a> {
}

#[derive(Debug)]
struct MyFormattedFields(String);
struct NodeName(String);

impl MyFormattedFields {
impl NodeName {
fn as_str(&self) -> &str {
self.0.as_str()
}
Expand Down Expand Up @@ -272,25 +291,23 @@ where
}

mod time {
use std::fmt;
use ansi_term::{Style};
use tracing_subscriber::fmt::time::FormatTime;

pub(crate) fn write<T>(timer: T, writer: &mut dyn fmt::Write, with_ansi: bool) -> fmt::Result
where
T: FormatTime,
{
if with_ansi {
let style = Style::new().dimmed();
write!(writer, "{}", style.prefix())?;
timer.format_time(writer)?;
write!(writer, "{}", style.suffix())?;
} else {
timer.format_time(writer)?;
use ansi_term::Style;
use std::fmt;
use tracing_subscriber::fmt::time::FormatTime;

pub(crate) fn write<T>(timer: T, writer: &mut dyn fmt::Write, with_ansi: bool) -> fmt::Result
where
T: FormatTime,
{
if with_ansi {
let style = Style::new().dimmed();
write!(writer, "{}", style.prefix())?;
timer.format_time(writer)?;
write!(writer, "{}", style.suffix())?;
} else {
timer.format_time(writer)?;
}
writer.write_char(' ')?;
Ok(())
}
writer.write_char(' ')?;
Ok(())
}
}


3 changes: 1 addition & 2 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
telemetry_connection_sinks,
} = params;

let abc = String::from("a\"b\'c");
let span = tracing::info_span!("substrate-node", name = config.network.node_name.as_str(), test = abc.as_str());
let span = tracing::info_span!("substrate-node", name = config.network.node_name.as_str());
let _enter = span.enter();

let chain_info = client.usage_info().chain;
Expand Down
45 changes: 0 additions & 45 deletions client/service/src/logger.rs

This file was deleted.

10 changes: 8 additions & 2 deletions client/telemetry/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,18 @@ impl TelemetryWorker {
}
};

let serialized = {
let mut out = Vec::new();
slog_json::Json::default(&mut out).log(record, values).map_err(|_| ())?;
out
};

// None of the nodes want that verbosity, so just return without doing any serialization.
if self.nodes.iter().all(|(_, node_max_verbosity)| msg_verbosity > *node_max_verbosity) {
trace!(
target: "telemetry",
"Skipping log entry because verbosity {:?} is too high for all endpoints",
msg_verbosity
"Skipping log entry because verbosity {:?} is too high for all endpoints: {}",
msg_verbosity, String::from_utf8(serialized).unwrap()
);
return Ok(())
}
Expand Down