6
6
indicatif:: { ProgressDrawTarget , ProgressStyle } ,
7
7
std:: {
8
8
borrow:: Cow ,
9
- env,
10
9
fmt:: Display ,
11
10
fs:: { File , OpenOptions } ,
12
11
path:: Path ,
13
12
process:: exit,
14
- thread:: JoinHandle ,
15
13
time:: Duration ,
16
14
} ,
17
15
} ;
@@ -22,69 +20,6 @@ pub mod cli;
22
20
pub mod commands;
23
21
pub mod dashboard;
24
22
25
- #[ cfg( unix) ]
26
- fn redirect_stderr ( filename : & str ) {
27
- use std:: os:: unix:: io:: AsRawFd ;
28
- match OpenOptions :: new ( ) . create ( true ) . append ( true ) . open ( filename) {
29
- Ok ( file) => unsafe {
30
- libc:: dup2 ( file. as_raw_fd ( ) , libc:: STDERR_FILENO ) ;
31
- } ,
32
- Err ( err) => eprintln ! ( "Unable to open {filename}: {err}" ) ,
33
- }
34
- }
35
-
36
- // Redirect stderr to a file with support for logrotate by sending a SIGUSR1 to the process.
37
- //
38
- // Upon success, future `log` macros and `eprintln!()` can be found in the specified log file.
39
- pub fn redirect_stderr_to_file ( logfile : Option < String > ) -> Option < JoinHandle < ( ) > > {
40
- // Default to RUST_BACKTRACE=1 for more informative validator logs
41
- if env:: var_os ( "RUST_BACKTRACE" ) . is_none ( ) {
42
- env:: set_var ( "RUST_BACKTRACE" , "1" )
43
- }
44
-
45
- match logfile {
46
- None => {
47
- solana_logger:: setup_with_default_filter ( ) ;
48
- None
49
- }
50
- Some ( logfile) => {
51
- #[ cfg( unix) ]
52
- {
53
- use log:: info;
54
- let mut signals =
55
- signal_hook:: iterator:: Signals :: new ( [ signal_hook:: consts:: SIGUSR1 ] )
56
- . unwrap_or_else ( |err| {
57
- eprintln ! ( "Unable to register SIGUSR1 handler: {err:?}" ) ;
58
- exit ( 1 ) ;
59
- } ) ;
60
-
61
- solana_logger:: setup_with_default_filter ( ) ;
62
- redirect_stderr ( & logfile) ;
63
- Some (
64
- std:: thread:: Builder :: new ( )
65
- . name ( "solSigUsr1" . into ( ) )
66
- . spawn ( move || {
67
- for signal in signals. forever ( ) {
68
- info ! (
69
- "received SIGUSR1 ({}), reopening log file: {:?}" ,
70
- signal, logfile
71
- ) ;
72
- redirect_stderr ( & logfile) ;
73
- }
74
- } )
75
- . unwrap ( ) ,
76
- )
77
- }
78
- #[ cfg( not( unix) ) ]
79
- {
80
- println ! ( "logrotate is not supported on this platform" ) ;
81
- solana_logger:: setup_file_with_default ( & logfile, solana_logger:: DEFAULT_FILTER ) ;
82
- None
83
- }
84
- }
85
- }
86
- }
87
-
88
23
pub fn format_name_value ( name : & str , value : & str ) -> String {
89
24
format ! ( "{} {}" , style( name) . bold( ) , value)
90
25
}
0 commit comments