-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): configurable log file location (#2380)
## Description Allows for Zarf's logs to still be sent to a log file, but be muted otherwise. ```go logFile, err := message.UseLogFile("") if err != nil { return err // handle the error as you see fit } location := message.LogFileLocation() // get the log file location if you want to // set pterm output to only go to this logfile pterm.SetDefaultOutput(logFile) // disable progress bars (otherwise they will still get printed to STDERR) message.NoProgress = true ``` ## Related Issue Fixes #2372 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Other (security config, docs update, etc) ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --------- Signed-off-by: razzle <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package message provides a rich set of functions for displaying messages to the user. | ||
package message | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
// pausableLogFile is a pausable log file | ||
type pausableLogFile struct { | ||
wr io.Writer | ||
f *os.File | ||
} | ||
|
||
// pause the log file | ||
func (l *pausableLogFile) pause() { | ||
l.wr = io.Discard | ||
} | ||
|
||
// resume the log file | ||
func (l *pausableLogFile) resume() { | ||
l.wr = l.f | ||
} | ||
|
||
// Write writes the data to the log file | ||
func (l *pausableLogFile) Write(p []byte) (n int, err error) { | ||
return l.wr.Write(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters