Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add support for asynchronous building and pushing of profiles#271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
PhilTaken wants to merge8 commits intoserokell:master
base:master
Choose a base branch
Loading
fromPhilTaken:phil/async-build-and-push
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
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
PrevPrevious commit
NextNext commit
wrap the logger with a custom implementation
the custom implementation handles indicatif's progressbars better so as to notleave orphaned progress bar fragments when logging while a progressbar is active
  • Loading branch information
@PhilTaken
PhilTaken committedSep 18, 2024
commit02b9681f7eddd2d386158eb5d36ad933a5d2fb88
7 changes: 4 additions & 3 deletionssrc/cli.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -431,6 +431,7 @@ async fn run_deploy(
boot: bool,
log_dir: &Option<String>,
rollback_succeeded: bool,
mp: MultiProgress,
) -> Result<(), RunDeployError> {
let to_deploy: ToDeploy = deploy_flakes
.iter()
Expand DownExpand Up@@ -618,9 +619,8 @@ async fn run_deploy(
});

// show progress information
let mp = MultiProgress::new();
let remote_mp = mp.clone();
let new_spinner = || ProgressBar::new_spinner().with_style(ProgressStyle::with_template("{spinner:.blue} {prefix} {msg}").unwrap().tick_strings(&["⢎ ", "⠎⠁", "⠊⠑", "⠈⠱", " ⡱", "⢀⡰", "⢄⡠", "⢆⡀"]));
let new_spinner = || ProgressBar::new_spinner().with_style(ProgressStyle::with_template("{spinner:.blue} {prefix} {msg}").expect("invalid template").tick_strings(&["⢎ ", "⠎⠁", "⠊⠑", "⠈⠱", " ⡱", "⢀⡰", "⢄⡠", "⢆⡀"]));

let (_remote_results, local_results) = join!(
// remote builds can be run asynchronously
Expand DownExpand Up@@ -765,7 +765,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
None => Opts::parse(),
};

deploy::init_logger(
let (mp, _handle) =deploy::init_logger(
opts.debug_logs,
opts.log_dir.as_deref(),
&deploy::LoggerType::Deploy,
Expand DownExpand Up@@ -830,6 +830,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
opts.boot,
&opts.log_dir,
opts.rollback_succeeded.unwrap_or(true),
mp
)
.await?;

Expand Down
68 changes: 62 additions & 6 deletionssrc/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
//
// SPDX-License-Identifier: MPL-2.0

use indicatif::MultiProgress;
use rnix::{types::*, SyntaxKind::*};

use merge::Merge;
Expand DownExpand Up@@ -101,19 +102,71 @@ pub enum LoggerType {
Revoke,
}

use log::Log;

pub struct LogWrapper {
bar: MultiProgress,
log: Box<dyn Log>,
}

impl LogWrapper {
pub fn new(bar: MultiProgress, log: Box<dyn Log>) -> Self {
Self { bar, log }
}

pub fn try_init(self) -> Result<(), log::SetLoggerError> {
use log::LevelFilter::*;
let levels = [Off, Error, Warn, Info, Debug, Trace];

for level_filter in levels.iter().rev() {
let level = if let Some(level) = level_filter.to_level() {
level
} else {
continue;
};
let meta = log::Metadata::builder().level(level).build();
if self.enabled(&meta) {
log::set_max_level(*level_filter);
break;
}
}

log::set_boxed_logger(Box::new(self))
}
pub fn multi(&self) -> MultiProgress {
self.bar.clone()
}
}

impl Log for LogWrapper {
fn enabled(&self, metadata: &log::Metadata) -> bool {
self.log.enabled(metadata)
}

fn log(&self, record: &log::Record) {
if self.log.enabled(record.metadata()) {
self.bar.suspend(|| self.log.log(record))
}
}

fn flush(&self) {
self.log.flush()
}
}

pub fn init_logger(
debug_logs: bool,
log_dir: Option<&str>,
logger_type: &LoggerType,
) -> Result<(), FlexiLoggerError> {
) -> Result<(MultiProgress, ReconfigurationHandle), FlexiLoggerError> {
let logger_formatter = match &logger_type {
LoggerType::Deploy => logger_formatter_deploy,
LoggerType::Activate => logger_formatter_activate,
LoggerType::Wait => logger_formatter_wait,
LoggerType::Revoke => logger_formatter_revoke,
};

if let Some(log_dir) = log_dir {
let (logger, handle) =if let Some(log_dir) = log_dir {
let mut logger = Logger::with_env_or_str("debug")
.log_to_file()
.format_for_stderr(logger_formatter)
Expand All@@ -132,7 +185,7 @@ pub fn init_logger(
LoggerType::Deploy => (),
}

logger.start()?;
logger.build()?
} else {
Logger::with_env_or_str(match debug_logs {
true => "debug",
Expand All@@ -141,10 +194,13 @@ pub fn init_logger(
.log_target(LogTarget::StdErr)
.format(logger_formatter)
.set_palette("196;208;51;7;8".to_string())
.start()?;
}
.build()?
};

let multi = MultiProgress::new();
LogWrapper::new(multi.clone(), logger).try_init().unwrap();

Ok(())
Ok((multi, handle))
}

pub mod cli;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp