Skip to content

Commit

Permalink
Fixed an issue with sys logs not working in Windows environment
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitesh-wingify committed Nov 3, 2023
1 parent 4abf226 commit 5c43d26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).## [1.25.0] - 2022-11-03

### Fixed

- Fixed an issue with sys logs not working in Windows environment

## [1.24.0] - 2022-08-04

Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/log_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
DebugMessageInvalidRequestTimeInterval = "requestTimeInterval hould be > %v and <= %v. Assigning it the default value i.e %v seconds"
DebugMessageInvalidEventsPerRequest = "eventsPerRequest should be >= %v and <= %v. Assigning it the default value i.e %v"
/*Extras*/
DebugMessageCustomLoggerFound = "[%v] Custom logger found"
DebugMessageCustomLoggerFound = "Custom logger found"
DebugMessageNoSegmentsInVariation = "[%v] For User ID: %v of Campaign: %v, segment was missing, hence skipping segmentation %v "
DebugMessageSettingsFileProcessed = "[%v] Settings file processed"
DebugMessageValidConfiguration = "[%v] SDK configuration and account settings are valid"
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func SetLogLevel(lvl int) {
}

// GetLogLevel function gets log level for logging
func GetLogLevel() (lvl int){
func GetLogLevel() (lvl int) {
lvl = logLevel
return
}
Expand Down
31 changes: 16 additions & 15 deletions pkg/logger/logger_syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
package logger

import (
"log/syslog"
"log"
"os"
)

func setup(src string) (*syslog.Writer, *syslog.Writer, *syslog.Writer, error) {
const facility = syslog.LOG_USER
il, err := syslog.New(facility|syslog.LOG_NOTICE, src)
if err != nil {
return nil, nil, nil, err
}
wl, err := syslog.New(facility|syslog.LOG_WARNING, src)
if err != nil {
return nil, nil, nil, err
}
el, err := syslog.New(facility|syslog.LOG_ERR, src)
if err != nil {
return nil, nil, nil, err
}
type LoggerWriter struct {
*log.Logger
}

func (lw *LoggerWriter) Write(p []byte) (n int, err error) {
lw.Print(string(p))
return len(p), nil
}

func setup(src string) (*LoggerWriter, *LoggerWriter, *LoggerWriter, error) {
il := &LoggerWriter{log.New(os.Stdout, src+" [INFO] ", log.LstdFlags)}
wl := &LoggerWriter{log.New(os.Stdout, src+" [WARNING] ", log.LstdFlags)}
el := &LoggerWriter{log.New(os.Stderr, src+" [ERROR] ", log.LstdFlags)}

return il, wl, el, nil
}

0 comments on commit 5c43d26

Please sign in to comment.