-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintain log buffer and flush errors at the end
- Loading branch information
Showing
4 changed files
with
52 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
package helpers | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
) | ||
|
||
var stderrLog = log.New(os.Stderr, "[Log] ", 0) | ||
var ErrLog *log.Logger | ||
|
||
const logPrefix = "[Log] " | ||
|
||
var logBuffer *bytes.Buffer | ||
|
||
func resetLog() { | ||
ErrLog = log.New(os.Stderr, "[Log] ", 0) | ||
} | ||
|
||
func init() { | ||
resetLog() | ||
} | ||
|
||
func EnableLogBuffer() { | ||
if logBuffer == nil { | ||
logBuffer = new(bytes.Buffer) | ||
ErrLog = log.New(logBuffer, logPrefix, 0) | ||
} | ||
} | ||
|
||
func DisableAndFlushLogBuffer() { | ||
if logBuffer != nil { | ||
os.Stderr.Write(logBuffer.Bytes()) | ||
logBuffer = nil | ||
resetLog() | ||
} | ||
} |
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