Skip to content

Commit

Permalink
refactor(log): shorten target name & add missing log
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Aug 1, 2022
1 parent 0e430b0 commit 89648da
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 30 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
SHORT_NAME: tg
CRATE_NAME: telegram-message-source
CRATE_NAME: msgist-tg

jobs:
prepare:
Expand Down Expand Up @@ -142,13 +142,6 @@ jobs:
- name: Compress
run: bash ./.github/compress.sh

- uses: dev-drprasad/delete-older-releases@v0.2.0
with:
keep_latest: 2
delete_tag_pattern: beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Github release
uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand All @@ -159,3 +152,11 @@ jobs:
files: |
packages/*
LICENSE
- name: Delete older releases
uses: dev-drprasad/delete-older-releases@v0.2.0
with:
keep_latest: 1
delete_tag_pattern: beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
SHORT_NAME: tg
CRATE_NAME: telegram-message-source
CRATE_NAME: msgist-tg

jobs:
compile:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "telegram-message-source"
name = "msgist-tg"
version = "1.7.0-rc1"
authors = ["Itsusinn <itsusinn@foxmail.com>"]
edition = "2021"
Expand Down
9 changes: 2 additions & 7 deletions src/handlers/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use crate::{

static CHANNEL: LateInit<UnboundedSender<(i64, ArcStr)>> = LateInit::new();

const TARGET: &str = "msgist::handlers";

pub fn recover() -> Result<()> {
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<(i64, ArcStr)>();
tokio::spawn(async move {
Expand Down Expand Up @@ -67,10 +65,7 @@ pub async fn nats_handler(message: nats::Message, target: ArcStr) -> Result<()>
Ok(v) => v,
Err(_e) => {
// todo logging
tracing::warn!(
target: TARGET,
"未知的数据包类型,请更新本消息源,若已是最新请等待适配"
);
tracing::warn!("未知的数据包类型,请更新本消息源,若已是最新请等待适配");
return Ok(());
}
};
Expand All @@ -95,7 +90,7 @@ async fn msg_handler(mut message: Message, target: i64) -> Result<()> {

let mut reunite_text = String::new();
for single in message.chain {
trace!(target:TARGET,element = ?single,"正在处理消息链中的元素");
trace!(element = ?single,"正在处理消息链中的元素");
match single {
MessageType::Text { content } => {
reunite_text.write_str(&html::escape(content.as_str()))?;
Expand Down
1 change: 0 additions & 1 deletion src/handlers/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
config::CONFIG,
ext::db::DbExt,
};
const TARGET: &str = "mesagisto::handlers";

#[instrument(skip(msg))]
pub async fn answer_common(msg: Message) -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub(crate) async fn init() -> Result<()> {
// TODO EnvFilter;
#[cfg(feature = "polylith")]
let filter = tracing_subscriber::filter::Targets::new()
.with_target("teloxide", Level::TRACE)
.with_target("telegram_message_source", Level::TRACE)
.with_target("mesagisto_client", Level::TRACE)
.with_target("msgist", Level::TRACE)
Expand All @@ -20,7 +19,7 @@ pub(crate) async fn init() -> Result<()> {

#[cfg(not(feature = "polylith"))]
let filter = tracing_subscriber::filter::Targets::new()
.with_target("telegram_message_source", Level::DEBUG)
.with_target("msgist_tg", Level::DEBUG)
.with_target("mesagisto_client", Level::DEBUG)
.with_target("teloxide", Level::INFO)
.with_default(Level::WARN);
Expand Down
16 changes: 6 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ mod net;
mod update;
mod webhook;

const TARGET: &str = "msgist";

#[tokio::main]
async fn main() -> Result<()> {
if cfg!(feature = "color") {
Expand All @@ -61,14 +59,13 @@ async fn run() -> Result<()> {
.replace('_', "-");
rust_i18n::set_locale(&locale);
info!(
target: TARGET,
"{}",
t!("log.locale-not-configured", locale_ = &locale)
);
}
if !CONFIG.enable {
warn!(target: TARGET, "{}", t!("log.not-enable"));
warn!(target: TARGET, "{}", t!("log.not-enable-helper"));
warn!("{}", t!("log.not-enable"));
warn!("{}", t!("log.not-enable-helper"));
return Ok(());
}
CONFIG.migrate();
Expand All @@ -82,14 +79,14 @@ async fn run() -> Result<()> {
tokio::task::spawn_blocking(|| {
match update::update() {
Ok(Status::UpToDate(_)) => {
info!(target: TARGET, "{}", t!("log.update-check-success"));
info!("{}", t!("log.update-check-success"));
}
Ok(Status::Updated(_)) => {
info!(target: TARGET, "{}", t!("log.upgrade-success"));
info!("{}", t!("log.upgrade-success"));
std::process::exit(0);
}
Err(e) => {
error!(target: TARGET, "{}", e);
error!("{}", e);
}
};
})
Expand All @@ -116,7 +113,6 @@ async fn run() -> Result<()> {
.apply()
.await?;
info!(
target: TARGET,
"{}",
t!("log.boot-start", version = env!("CARGO_PKG_VERSION"))
);
Expand All @@ -132,7 +128,7 @@ async fn run() -> Result<()> {
});
tokio::signal::ctrl_c().await?;
CONFIG.save().await.expect("保存配置文件失败");
info!(target: TARGET, "{}", t!("log.shutdown"));
info!("{}", t!("log.shutdown"));

#[cfg(feature = "polylith")]
opentelemetry::global::shutdown_tracer_provider();
Expand Down

0 comments on commit 89648da

Please sign in to comment.