ant_node/
log_markers.rs

1// Copyright 2024 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
4// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
5// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
6// KIND, either express or implied. Please review the Licences for the specific language governing
7// permissions and limitations relating to use of the SAFE Network Software.
8
9use crate::error::PutValidationError;
10use ant_protocol::PrettyPrintRecordKey;
11use libp2p::{PeerId, kad::RecordKey};
12use strum::Display;
13
14/// Public Markers for generating log output,
15/// These generate appropriate log level output and consistent strings.
16/// Changing these log markers is a breaking change.
17#[derive(Debug, Clone, Display, Copy)]
18pub enum Marker<'a> {
19    /// The node has started
20    NodeConnectedToNetwork,
21
22    /// Peer was added to the routing table
23    PeerAddedToRoutingTable(&'a PeerId),
24
25    /// Peer was removed from the routing table
26    PeerRemovedFromRoutingTable(&'a PeerId),
27
28    /// The number of peers in the routing table
29    PeersInRoutingTable(usize),
30
31    /// Interval based replication
32    IntervalReplicationTriggered,
33
34    /// Keys of Records we are fetching to replicate locally
35    FetchingKeysForReplication {
36        /// fetching_keys_len: number of keys we are fetching from network
37        fetching_keys_len: usize,
38    },
39
40    /// Valid non-existing Chunk record PUT from the network received and stored
41    ValidChunkRecordPutFromNetwork(&'a PrettyPrintRecordKey<'a>),
42    /// Valid non-existing GraphEntry record PUT from the network received and stored
43    ValidGraphEntryRecordPutFromNetwork(&'a PrettyPrintRecordKey<'a>),
44    /// Valid Scratchpad record PUT from the network received and stored
45    ValidScratchpadRecordPutFromNetwork(&'a PrettyPrintRecordKey<'a>),
46
47    /// Valid paid to us and royalty paid chunk stored
48    ValidPaidChunkPutFromClient(&'a PrettyPrintRecordKey<'a>),
49    /// Valid GraphEntry stored
50    ValidGraphEntryPutFromClient(&'a PrettyPrintRecordKey<'a>),
51    /// Valid scratchpad stored
52    ValidScratchpadRecordPutFromClient(&'a PrettyPrintRecordKey<'a>),
53
54    /// Valid paid to us and royalty paid pointer stored
55    ValidPointerPutFromClient(&'a PrettyPrintRecordKey<'a>),
56
57    /// Record rejected
58    RecordRejected(&'a PrettyPrintRecordKey<'a>, &'a PutValidationError),
59
60    /// Interval based bad_nodes check
61    IntervalBadNodesCheckTriggered,
62}
63
64impl Marker<'_> {
65    /// Returns the string representation of the LogMarker.
66    pub fn log(&self) {
67        // Down the line, if some logs are noisier than others, we can
68        // match the type and log a different level.
69        info!("{self:?}");
70    }
71
72    /// Helper to log the FetchingKeysForReplication variant
73    pub fn fetching_keys_for_replication(keys: &[(PeerId, RecordKey)]) -> Self {
74        Marker::FetchingKeysForReplication {
75            fetching_keys_len: keys.len(),
76        }
77    }
78}