feat: proper logging
This commit is contained in:
parent
8d2cf29b83
commit
eb5117e21f
|
@ -50,12 +50,70 @@ dependencies = [
|
|||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.80"
|
||||
|
@ -306,6 +364,33 @@ dependencies = [
|
|||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colog"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c426b7af8d5e0ad79de6713996632ce31f0d68ba84068fb0d654b396e519df0"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"env_logger",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.12"
|
||||
|
@ -349,6 +434,29 @@ version = "1.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"humantime",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
|
@ -577,6 +685,12 @@ version = "1.8.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "1.3.1"
|
||||
|
@ -681,6 +795,12 @@ version = "2.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
|
@ -705,6 +825,12 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
|
@ -774,7 +900,9 @@ dependencies = [
|
|||
name = "mostr"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"colog",
|
||||
"itertools",
|
||||
"log",
|
||||
"nostr-sdk",
|
||||
"once_cell",
|
||||
"tokio",
|
||||
|
@ -1070,6 +1198,35 @@ dependencies = [
|
|||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.4"
|
||||
|
@ -1613,6 +1770,12 @@ version = "0.7.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
|
|
@ -12,8 +12,10 @@ default-run = "mostr"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
xdg = "2.5.2"
|
||||
itertools = "0.12.1"
|
||||
log = "0.4.21"
|
||||
colog = "1.3.0"
|
||||
nostr-sdk = "0.30"
|
||||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
once_cell = "1.19.0"
|
||||
xdg = "2.5.2"
|
||||
itertools = "0.12.1"
|
||||
once_cell = "1.19.0"
|
31
src/main.rs
31
src/main.rs
|
@ -8,6 +8,7 @@ use std::str::FromStr;
|
|||
use std::sync::mpsc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::prelude::*;
|
||||
use xdg::BaseDirectories;
|
||||
|
||||
|
@ -46,7 +47,7 @@ fn or_print<T, U: Display>(result: Result<T, U>) -> Option<T> {
|
|||
match result {
|
||||
Ok(value) => Some(value),
|
||||
Err(error) => {
|
||||
eprintln!("{}", error);
|
||||
warn!("{}", error);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +64,8 @@ fn prompt(prompt: &str) -> Option<String> {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
colog::init();
|
||||
|
||||
let config_dir = or_print(BaseDirectories::new())
|
||||
.and_then(|d| or_print(d.create_config_directory("mostr")))
|
||||
.unwrap_or(PathBuf::new());
|
||||
|
@ -72,7 +75,7 @@ async fn main() {
|
|||
let keys = match fs::read_to_string(&keysfile).map(|s| Keys::from_str(&s)) {
|
||||
Ok(Ok(key)) => key,
|
||||
_ => {
|
||||
eprintln!("Could not read keys from {}", keysfile.to_string_lossy());
|
||||
warn!("Could not read keys from {}", keysfile.to_string_lossy());
|
||||
let keys = prompt("Secret Key?")
|
||||
.and_then(|s| or_print(Keys::from_str(&s)))
|
||||
.unwrap_or_else(|| Keys::generate());
|
||||
|
@ -82,7 +85,7 @@ async fn main() {
|
|||
};
|
||||
|
||||
let client = Client::new(&keys);
|
||||
println!("My public key: {}", keys.public_key());
|
||||
info!("My public key: {}", keys.public_key());
|
||||
match var("MOSTR_RELAY") {
|
||||
Ok(relay) => {
|
||||
or_print(client.add_relay(relay).await);
|
||||
|
@ -94,7 +97,7 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Could not read relays file: {}", e);
|
||||
warn!("Could not read relays file: {}", e);
|
||||
if let Some(line) = prompt("Relay?") {
|
||||
let url = if line.contains("://") {
|
||||
line
|
||||
|
@ -146,7 +149,7 @@ async fn main() {
|
|||
});
|
||||
|
||||
let sub_id: SubscriptionId = client.subscribe(vec![Filter::new()], None).await;
|
||||
eprintln!("Subscribed with {}", sub_id);
|
||||
info!("Subscribed with {}", sub_id);
|
||||
let mut notifications = client.notifications();
|
||||
|
||||
/*println!("Finding existing events");
|
||||
|
@ -170,10 +173,11 @@ async fn main() {
|
|||
|
||||
let sender = tokio::spawn(async move {
|
||||
while let Ok(e) = rx.recv() {
|
||||
//eprintln!("Sending {}", e.id);
|
||||
trace!("Sending {}", e.id);
|
||||
// TODO send in batches
|
||||
let _ = client.send_event(e).await;
|
||||
}
|
||||
println!("Stopping listeners...");
|
||||
info!("Stopping listeners...");
|
||||
client.unsubscribe_all().await;
|
||||
});
|
||||
for argument in args().skip(1) {
|
||||
|
@ -193,6 +197,7 @@ async fn main() {
|
|||
stdout().flush().unwrap();
|
||||
match lines.next() {
|
||||
Some(Ok(input)) => {
|
||||
let mut count = 0;
|
||||
while let Ok(notification) = notifications.try_recv() {
|
||||
if let RelayPoolNotification::Event {
|
||||
subscription_id,
|
||||
|
@ -202,8 +207,12 @@ async fn main() {
|
|||
{
|
||||
print_event(&event);
|
||||
tasks.add(*event);
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
info!("Received {count} updates");
|
||||
}
|
||||
|
||||
let mut iter = input.chars();
|
||||
let op = iter.next();
|
||||
|
@ -261,7 +270,7 @@ async fn main() {
|
|||
|
||||
Some('|') | Some('/') => match tasks.get_position() {
|
||||
None => {
|
||||
println!("First select a task to set its state!");
|
||||
warn!("First select a task to set its state!");
|
||||
}
|
||||
Some(id) => {
|
||||
tasks.set_state_for(&id, arg);
|
||||
|
@ -337,7 +346,7 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(Err(e)) => eprintln!("{}", e),
|
||||
Some(Err(e)) => warn!("{}", e),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
@ -352,12 +361,12 @@ async fn main() {
|
|||
});
|
||||
drop(tasks);
|
||||
|
||||
eprintln!("Submitting pending changes...");
|
||||
info!("Submitting pending changes...");
|
||||
or_print(sender.await);
|
||||
}
|
||||
|
||||
fn print_event(event: &Event) {
|
||||
eprintln!(
|
||||
debug!(
|
||||
"At {} found {} kind {} '{}' {:?}",
|
||||
event.created_at, event.id, event.kind, event.content, event.tags
|
||||
);
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::ops::Div;
|
|||
|
||||
use itertools::Either::{Left, Right};
|
||||
use itertools::Itertools;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, Kind, Tag, Timestamp};
|
||||
|
||||
use crate::EventSender;
|
||||
|
@ -159,7 +160,7 @@ impl Task {
|
|||
"descriptions" => Some(format!("{:?}", self.descriptions().collect::<Vec<&String>>())),
|
||||
"desc" | "description" => self.descriptions().last().cloned(),
|
||||
_ => {
|
||||
eprintln!("Unknown task property {}", property);
|
||||
warn!("Unknown task property {}", property);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::iter::once;
|
||||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, Tag};
|
||||
use nostr_sdk::Tag::Hashtag;
|
||||
|
||||
|
@ -296,7 +297,7 @@ impl Tasks {
|
|||
t.children.insert(event.id);
|
||||
});
|
||||
if self.tasks.contains_key(&event.id) {
|
||||
//eprintln!("Did not insert duplicate event {}", event.id);
|
||||
debug!("Did not insert duplicate event {}", event.id);
|
||||
} else {
|
||||
self.tasks.insert(event.id, Task::new(event));
|
||||
}
|
||||
|
@ -342,7 +343,7 @@ impl Tasks {
|
|||
|
||||
pub(crate) fn add_note(&mut self, note: &str) {
|
||||
match self.position {
|
||||
None => eprintln!("Cannot add note '{}' without active task", note),
|
||||
None => warn!("Cannot add note '{}' without active task", note),
|
||||
Some(id) => {
|
||||
self.sender
|
||||
.submit(EventBuilder::text_note(note, vec![]))
|
||||
|
@ -406,7 +407,7 @@ fn test_depth() {
|
|||
let task1 = tasks.get_by_id(&t1.unwrap()).unwrap();
|
||||
assert_eq!(tasks.depth, 1);
|
||||
assert_eq!(task1.state().unwrap().get_label(), "Open");
|
||||
//eprintln!("{:?}", tasks);
|
||||
debug!("{:?}", tasks);
|
||||
assert_eq!(tasks.current_tasks().len(), 1);
|
||||
tasks.depth = 0;
|
||||
assert_eq!(tasks.current_tasks().len(), 0);
|
||||
|
|
Loading…
Reference in New Issue