Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken format to log file #888

Closed
quancore opened this issue Jan 16, 2019 · 2 comments
Closed

broken format to log file #888

quancore opened this issue Jan 16, 2019 · 2 comments

Comments

@quancore
Copy link

I am logging console as well as txt log file.Console output is okay and it is colored however, txt output is broken. Here is the output:
log.txt
Here is the code to setup logger:

// InitLogger setup logger for both printing file and console
func InitLogger(path string, methodname bool) {
// remove old file if exist
os.Remove(path)
// set formatter of logger
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
DisableTimestamp: true,
})
// open logging file
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0666)
// check error
CheckError(err)
// defer f.Close()
// log both file and console
wrt := io.MultiWriter(os.Stdout, f)
// set output
log.SetOutput(wrt)
// set whether we log filename as well
log.SetReportCaller(methodname)
// log.SetLevel(log.ErrorLevel)
log.Info("Logger has been initilized.")
}

@richpoirier
Copy link
Collaborator

Hi @quancore. See these issues: #780 and #784.

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2020
@stale stale bot closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants