-
Notifications
You must be signed in to change notification settings - Fork 264
rpc: implement logs subscription #5092
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
893f831
90c0f99
e9edd94
0f54e7b
0b7cc0e
a35f734
dfaeaa6
189626d
8584fca
1057e79
505a56c
2a4e6b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,12 +128,22 @@ fn run_app_inner( | |||||||||||||||
| let is_silent_logging = is_silent_logging(cmd); | ||||||||||||||||
| let (mut handle, mut handle_stop_rx, _runtime) = new_global_runtime(None); | ||||||||||||||||
| let setup = Setup::from_matches(bin_name, cmd, matches)?; | ||||||||||||||||
| let _guard = SetupGuard::from_setup(&setup, &version, handle.clone(), is_silent_logging)?; | ||||||||||||||||
| // Disable logging here if the user is executing `ckb run`. Logs subscription of RPC service requires access to `struct Shared`, so logger of `ckb run` will be initialized in `subcommand::run`. | ||||||||||||||||
| let (_guard, log_config) = if cmd == cli::CMD_RUN { | ||||||||||||||||
| SetupGuard::from_setup(&setup, &version, handle.clone(), is_silent_logging, false)? | ||||||||||||||||
| } else { | ||||||||||||||||
| SetupGuard::from_setup(&setup, &version, handle.clone(), is_silent_logging, true)? | ||||||||||||||||
| }; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simpler ?
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||||||||||||
|
|
||||||||||||||||
| raise_fd_limit(); | ||||||||||||||||
|
|
||||||||||||||||
| let ret = match cmd { | ||||||||||||||||
| cli::CMD_RUN => subcommand::run(setup.run(matches)?, version, handle.clone()), | ||||||||||||||||
| cli::CMD_RUN => subcommand::run( | ||||||||||||||||
| setup.run(matches)?, | ||||||||||||||||
| version, | ||||||||||||||||
| handle.clone(), | ||||||||||||||||
| log_config.unwrap(), | ||||||||||||||||
| ), | ||||||||||||||||
| cli::CMD_MINER => subcommand::miner(setup.miner(matches)?, handle.clone()), | ||||||||||||||||
| cli::CMD_REPLAY => subcommand::replay(setup.replay(matches)?, handle.clone()), | ||||||||||||||||
| cli::CMD_EXPORT => subcommand::export(setup.export(matches)?, handle.clone()), | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,10 +6,10 @@ use ckb_metrics_service::{self, Guard as MetricsInitGuard}; | |||||
|
|
||||||
| use crate::setup::Setup; | ||||||
|
|
||||||
| const CKB_LOG_ENV: &str = "CKB_LOG"; | ||||||
| pub const CKB_LOG_ENV: &str = "CKB_LOG"; | ||||||
|
|
||||||
| pub struct SetupGuard { | ||||||
| _logger_guard: LoggerInitGuard, | ||||||
| _logger_guard: Option<LoggerInitGuard>, | ||||||
| #[cfg(feature = "with_sentry")] | ||||||
| _sentry_guard: Option<sentry::ClientInitGuard>, | ||||||
| _metrics_guard: MetricsInitGuard, | ||||||
|
|
@@ -22,18 +22,23 @@ impl SetupGuard { | |||||
| version: &Version, | ||||||
| async_handle: Handle, | ||||||
| silent_logging: bool, | ||||||
| ) -> Result<Self, ExitCode> { | ||||||
| enable_logging: bool, | ||||||
| ) -> Result<(Self, Option<ckb_logger_config::Config>), ExitCode> { | ||||||
| // Initialization of logger must do before sentry, since `logger::init()` and | ||||||
| // `sentry_config::init()` both registers custom panic hooks, but `logger::init()` | ||||||
| // replaces all hooks previously registered. | ||||||
| let logger_guard = if silent_logging { | ||||||
| ckb_logger_service::init_silent()? | ||||||
| let logger_guard = if enable_logging { | ||||||
| Some(if silent_logging { | ||||||
| ckb_logger_service::init_silent()? | ||||||
| } else { | ||||||
| let mut logger_config = setup.config.logger().to_owned(); | ||||||
| if logger_config.emit_sentry_breadcrumbs.is_none() { | ||||||
| logger_config.emit_sentry_breadcrumbs = Some(setup.is_sentry_enabled); | ||||||
| } | ||||||
| ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config, None)? | ||||||
| }) | ||||||
| } else { | ||||||
| let mut logger_config = setup.config.logger().to_owned(); | ||||||
| if logger_config.emit_sentry_breadcrumbs.is_none() { | ||||||
| logger_config.emit_sentry_breadcrumbs = Some(setup.is_sentry_enabled); | ||||||
| } | ||||||
| ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config)? | ||||||
| None | ||||||
| }; | ||||||
|
|
||||||
| let sentry_guard = if setup.is_sentry_enabled { | ||||||
|
|
@@ -67,11 +72,14 @@ impl SetupGuard { | |||||
| ExitCode::Config | ||||||
| })?; | ||||||
|
|
||||||
| Ok(Self { | ||||||
| _logger_guard: logger_guard, | ||||||
| _sentry_guard: sentry_guard, | ||||||
| _metrics_guard: metrics_guard, | ||||||
| }) | ||||||
| Ok(( | ||||||
| Self { | ||||||
| _logger_guard: logger_guard, | ||||||
| _sentry_guard: sentry_guard, | ||||||
| _metrics_guard: metrics_guard, | ||||||
| }, | ||||||
| Some(setup.config.logger().to_owned()), | ||||||
| )) | ||||||
| } | ||||||
|
|
||||||
| #[cfg(not(feature = "with_sentry"))] | ||||||
|
|
@@ -80,12 +88,18 @@ impl SetupGuard { | |||||
| _version: &Version, | ||||||
| async_handle: Handle, | ||||||
| silent_logging: bool, | ||||||
| ) -> Result<Self, ExitCode> { | ||||||
| let logger_guard = if silent_logging { | ||||||
| ckb_logger_service::init_silent()? | ||||||
| // For ckb run, logging can be disabled here, since it requires `Shared` to create a logger that will be used for `ckb run` | ||||||
| enable_logging: bool, | ||||||
| ) -> Result<(Self, Option<ckb_logger_config::Config>), ExitCode> { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||
| let logger_guard = if enable_logging { | ||||||
| Some(if silent_logging { | ||||||
| ckb_logger_service::init_silent()? | ||||||
| } else { | ||||||
| let logger_config = setup.config.logger().to_owned(); | ||||||
| ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config, None)? | ||||||
| }) | ||||||
| } else { | ||||||
| let logger_config = setup.config.logger().to_owned(); | ||||||
| ckb_logger_service::init(Some(CKB_LOG_ENV), logger_config)? | ||||||
| None | ||||||
| }; | ||||||
|
|
||||||
| let metrics_config = setup.config.metrics().to_owned(); | ||||||
|
|
@@ -95,9 +109,12 @@ impl SetupGuard { | |||||
| ExitCode::Config | ||||||
| })?; | ||||||
|
|
||||||
| Ok(Self { | ||||||
| _logger_guard: logger_guard, | ||||||
| _metrics_guard: metrics_guard, | ||||||
| }) | ||||||
| Ok(( | ||||||
| Self { | ||||||
| _logger_guard: logger_guard, | ||||||
| _metrics_guard: metrics_guard, | ||||||
| }, | ||||||
| Some(setup.config.logger().to_owned()), | ||||||
| )) | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use multiple lines for long comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed