Skip to content

Commit d85758b

Browse files
isaac-fletchermeta-codesync[bot]
authored andcommitted
Replace fmt with proper logging in blocks (#570)
Summary: Pull Request resolved: #570 This change improves logging consistency by replacing direct `fmt.Printf` and `fmt.Println` calls with the structured logging package throughout the blocks package. Additionally updated testutils to not print to the screen. This ensures all logging output uses the proper logging infrastructure (`logging.L().Errorf()` and `logging.L().Infof()`) which provides better log formatting, filtering, and consistency across the application. Reviewed By: RoboticPrism Differential Revision: D85156300 fbshipit-source-id: 7ac8e679c2600a9079dd8b7ee84fe7e0d208e84e
1 parent 7ab3580 commit d85758b

File tree

4 files changed

+3
-5
lines changed

4 files changed

+3
-5
lines changed

pkg/blocks/expectstep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (s *ExpectStep) Execute(execCtx TTPExecutionContext) (*ActResult, error) {
184184
}
185185
defer func() {
186186
if err := os.Chdir(originalDir); err != nil {
187-
fmt.Printf("failed to change back to original directory: %v\n", err)
187+
logging.L().Errorf("failed to change back to original directory: %w", err)
188188
}
189189
}()
190190

pkg/blocks/killprocess.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func (s *KillProcessStep) Validate(_ TTPExecutionContext) error {
6060
return fmt.Errorf("Both Process ID and Process Name cannot be empty")
6161
}
6262
if s.ProcessID == "" {
63-
fmt.Printf("Processing using process name: %v\n", s.ProcessName)
63+
logging.L().Infof("Processing using process name: %v", s.ProcessName)
6464
return nil
6565
}
6666
// Not handling for overflow
6767
processID, err := strconv.Atoi(s.ProcessID)
6868
if err != nil {
69-
fmt.Printf("Failed to convert %v to int: %v\n", s.ProcessID, err)
69+
logging.L().Errorf("Failed to convert %v to int: %w", s.ProcessID, err)
7070
return fmt.Errorf("Invalid Process ID: %v", s.ProcessID)
7171
}
7272

pkg/testutils/kill_unix.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func CreateProcessToTerminate() (int, error) {
3232
cmd := exec.Command("ping", "-n", "60", "127.0.0.1")
3333
err := cmd.Start()
3434
if err != nil {
35-
fmt.Println("Failed to start process:", err)
3635
return 0, fmt.Errorf("Failed to start process: %w", err)
3736
}
3837
pid := cmd.Process.Pid

pkg/testutils/kill_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func CreateProcessToTerminate() (int, error) {
3232
cmd := exec.Command("cmd.exe", "/C", "ping -n 60 127.0.0.1 > nul")
3333
err := cmd.Start()
3434
if err != nil {
35-
fmt.Println("Failed to start process:", err)
3635
return 0, fmt.Errorf("Failed to start process: %w", err)
3736
}
3837
pid := cmd.Process.Pid

0 commit comments

Comments
 (0)