added env_logger
This commit is contained in:
parent
06789abc9f
commit
d022bac73e
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -102,6 +102,17 @@ dependencies = [
|
|||||||
"tungstenite",
|
"tungstenite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -330,6 +341,19 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fake-simd"
|
name = "fake-simd"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@ -592,6 +616,12 @@ version = "0.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
|
checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.13.8"
|
version = "0.13.8"
|
||||||
@ -1143,6 +1173,7 @@ dependencies = [
|
|||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"custom_error",
|
"custom_error",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"env_logger",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
@ -1529,6 +1560,15 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
@ -1968,6 +2008,15 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -13,6 +13,7 @@ sqlx = { version = "0.3.5", default-features = false, features = ["runtime-tokio
|
|||||||
regex = "1.3.9"
|
regex = "1.3.9"
|
||||||
async-trait = "0.1.36"
|
async-trait = "0.1.36"
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
|
env_logger = "0.8.1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
chrono-tz = "0.5"
|
chrono-tz = "0.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
44
src/main.rs
44
src/main.rs
@ -36,6 +36,8 @@ use crate::{
|
|||||||
|
|
||||||
use serenity::futures::TryFutureExt;
|
use serenity::futures::TryFutureExt;
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
struct SQLPool;
|
struct SQLPool;
|
||||||
|
|
||||||
impl TypeMapKey for SQLPool {
|
impl TypeMapKey for SQLPool {
|
||||||
@ -56,6 +58,8 @@ impl TypeMapKey for FrameworkCtx {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
dotenv()?;
|
dotenv()?;
|
||||||
|
|
||||||
let token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");
|
let token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");
|
||||||
@ -137,7 +141,45 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||||||
data.insert::<FrameworkCtx>(framework_arc);
|
data.insert::<FrameworkCtx>(framework_arc);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.start_autosharded().await?;
|
if let Ok((Some(lower), Some(upper))) = env::var("SHARD_RANGE").map(|sr| {
|
||||||
|
let mut split = sr
|
||||||
|
.split(',')
|
||||||
|
.map(|val| val.parse::<u64>().expect("SHARD_RANGE not an integer"));
|
||||||
|
|
||||||
|
(split.next(), split.next())
|
||||||
|
}) {
|
||||||
|
let total_shards = env::var("SHARD_COUNT")
|
||||||
|
.map(|shard_count| shard_count.parse::<u64>().ok())
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.expect("No SHARD_COUNT provided, but SHARD_RANGE was provided");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
lower < upper,
|
||||||
|
"SHARD_RANGE lower limit is not less than the upper limit"
|
||||||
|
);
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Starting client fragment with shards {}-{}/{}",
|
||||||
|
lower, upper, total_shards
|
||||||
|
);
|
||||||
|
|
||||||
|
client
|
||||||
|
.start_shard_range([lower, upper], total_shards)
|
||||||
|
.await?;
|
||||||
|
} else if let Ok(total_shards) = env::var("SHARD_COUNT").map(|shard_count| {
|
||||||
|
shard_count
|
||||||
|
.parse::<u64>()
|
||||||
|
.expect("SHARD_COUNT not an integer")
|
||||||
|
}) {
|
||||||
|
info!("Starting client with {} shards", total_shards);
|
||||||
|
|
||||||
|
client.start_shards(total_shards).await?;
|
||||||
|
} else {
|
||||||
|
info!("Starting client as autosharded");
|
||||||
|
|
||||||
|
client.start_autosharded().await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user