-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use base names for source files in log messages; colorize
- Loading branch information
Showing
2 changed files
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package log | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const ( | ||
colorBlack = iota + 30 | ||
colorRed | ||
colorGreen | ||
colorYellow | ||
colorBlue | ||
colorMagenta | ||
colorCyan | ||
colorWhite | ||
|
||
colorBold = 1 | ||
colorDarkGray = 90 | ||
) | ||
|
||
// colorize returns the string s wrapped in ANSI code c, unless disabled is true or c is 0. | ||
func colorize(s interface{}, c int, disabled bool) string { | ||
e := os.Getenv("NO_COLOR") | ||
if e != "" || c == 0 { | ||
disabled = true | ||
} | ||
|
||
if disabled { | ||
return fmt.Sprintf("%s", s) | ||
} | ||
return fmt.Sprintf("\x1b[%dm%v\x1b[0m", c, s) | ||
} |
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