Skip to content

Commit

Permalink
Add option to allow Emojis in log output
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Oct 23, 2024
1 parent 19f67fa commit 6004f54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion artifactory/services/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (rs *RepositoriesService) GetWithFilter(params RepositoriesFilterParams) (*
// This function is used to create the URL for the repositories API with the given filter params.
// The function expects to get a RepositoriesFilterParams struct that contains the desired filter params.
// The function returns the URL string.
func (rs *RepositoriesService)createUrlWithFilter(params RepositoriesFilterParams) string {
func (rs *RepositoriesService) createUrlWithFilter(params RepositoriesFilterParams) string {
u := url.URL{
Path: apiRepositories,
}
Expand Down
23 changes: 15 additions & 8 deletions utils/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ func NewLogger(logLevel LevelType, logToWriter io.Writer) *jfrogLogger {
}

type jfrogLogger struct {
LogLevel LevelType
OutputLog *log.Logger
DebugLog *log.Logger
InfoLog *log.Logger
WarnLog *log.Logger
ErrorLog *log.Logger
LogLevel LevelType
AllowEmojis bool
OutputLog *log.Logger
DebugLog *log.Logger
InfoLog *log.Logger
WarnLog *log.Logger
ErrorLog *log.Logger
}

func SetLogger(newLogger Log) {
Expand Down Expand Up @@ -96,6 +97,10 @@ func (logger *jfrogLogger) SetOutputWriter(writer io.Writer) {
logger.OutputLog = log.New(outputWriter, "", 0)
}

func (logger *jfrogLogger) SetAllowEmojis(allow bool) {
logger.AllowEmojis = allow
}

// Set the logs' writer to Stderr unless an alternative one is provided.
// In case the writer is set for file, colors will not be in use.
// Log flags to modify the log prefix as described in https://pkg.go.dev/log#pkg-constants.
Expand Down Expand Up @@ -189,11 +194,13 @@ func (logger jfrogLogger) Output(a ...interface{}) {
}

func (logger *jfrogLogger) Println(log *log.Logger, isTerminal bool, values ...interface{}) {
// Remove emojis from all strings if it's not a terminal or if the terminal is not supporting colors
// If not requested, remove emojis from all strings if it's not a terminal or if the terminal is not supporting colors
if !(IsColorsSupported() && isTerminal) {
for i, value := range values {
if str, ok := value.(string); ok {
if gomoji.ContainsEmoji(str) {
if logger.AllowEmojis {
values[i] = str
} else if gomoji.ContainsEmoji(str) {
values[i] = gomoji.RemoveEmojis(str)
}
}
Expand Down

0 comments on commit 6004f54

Please sign in to comment.