@@ -4,12 +4,30 @@ use crate::{
44} ;
55use log:: * ;
66use simplelog:: SharedLogger ;
7- use std:: io:: Write ;
7+ use std:: { env , io:: Write } ;
88
99/// A logger that prints logs in the format expected by GitHub Actions, with grouping support.
1010///
1111/// See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
12- pub struct GithubActionLogger ;
12+ pub struct GithubActionLogger {
13+ log_level : LevelFilter ,
14+ }
15+
16+ impl GithubActionLogger {
17+ pub fn new ( ) -> Self {
18+ // Only enable debug logging if it's enabled in Github Actions.
19+ let log_level = if env:: var ( "RUNNER_DEBUG" ) . unwrap_or_default ( ) == "1" {
20+ LevelFilter :: Debug
21+ } else {
22+ env:: var ( "CODSPEED_LOG" )
23+ . ok ( )
24+ . and_then ( |log_level| log_level. parse :: < LevelFilter > ( ) . ok ( ) )
25+ . unwrap_or ( LevelFilter :: Info )
26+ } ;
27+
28+ Self { log_level }
29+ }
30+ }
1331
1432impl Log for GithubActionLogger {
1533 fn enabled ( & self , _metadata : & Metadata ) -> bool {
@@ -40,6 +58,10 @@ impl Log for GithubActionLogger {
4058 return ;
4159 }
4260
61+ if level > self . log_level {
62+ return ;
63+ }
64+
4365 let prefix = match level {
4466 Level :: Error => "::error::" ,
4567 Level :: Warn => "::warning::" ,
@@ -60,9 +82,7 @@ impl Log for GithubActionLogger {
6082
6183impl SharedLogger for GithubActionLogger {
6284 fn level ( & self ) -> LevelFilter {
63- // since TRACE and DEBUG use ::debug::, we always enable them and let GitHub handle the filtering
64- // thanks to https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging
65- LevelFilter :: Trace
85+ self . log_level
6686 }
6787
6888 fn config ( & self ) -> Option < & simplelog:: Config > {
0 commit comments