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

Logger is not working when using "go run" #2

Closed
JamesCullum opened this issue Sep 11, 2016 · 4 comments
Closed

Logger is not working when using "go run" #2

JamesCullum opened this issue Sep 11, 2016 · 4 comments

Comments

@JamesCullum
Copy link

JamesCullum commented Sep 11, 2016

Run on Win32 during development

When i use the code from the example but execute the file via "go run main.go", it tries to navigate through temporary folders to save the log.

E17:39:53 logger.go:350] open ./log/C:\Users\USERNAME\AppData\Local\Temp\go-build405325394\command-line-arguments_obj\exe\main.exe.COMPUTERNAME.USERNAME.log.ERROR.20160911-608393956683: The filename, directory name, or volume label syntax is incorrect.

I used this code from the example for creation

logger.Init("./log", // specify the directory to save the logfiles
            1000, // maximum logfiles allowed under the specified log directory
            20, // number of logfiles to delete when number of logfiles exceeds the configured limit
            50, // maximum size of a logfile in MB
            false)

The problem is that the variable gProgname is being used, which is used like this

Line 521: var gProgname = path.Base(os.Args[0])
Line 289: conf.pathPrefix = conf.logPath + gProgname + "." + host + "." + username + ".log."

When using the run command, the executioning arguments change

@antigloss
Copy link
Owner

Please try this:

     logger.Init("C:\log", ...

在 2016年9月11日 23:50,JamesCullum notifications@github.com写道:Run on Win32 during development

When i use the code from the example but execute the file via "go run main.go", it tries to navigate through temporary folders to save the log.

E17:39:53 logger.go:350] open ./log/C:\Users\USERNAME\AppData\Local\Temp\go-build405325394\command-line-arguments_obj\exe\main.exe.COMPUTERNAME.USERNAME.log.ERROR.20160911-608393956683: The filename, directory name, or volume label syntax is incorrect.

I used this code from the example for creation

logger.Init("./log", // specify the directory to save the logfiles
1000, // maximum logfiles allowed under the specified log directory
20, // number of logfiles to delete when number of logfiles exceeds the configured limit
50, // maximum size of a logfile in MB
false)

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/antigloss/go","title":"antigloss/go","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/antigloss/go"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Logger is not working when using "go run" (#2)"}],"action":{"name":"View Issue","url":"https://github.com/antigloss/go/issues/2"}}}

@JamesCullum
Copy link
Author

I fixed it myself by simply removing the program name from the filename, as it was undocumented and counter intuitive anyways. I will make a PR later on with my changes.

@antigloss
Copy link
Owner

Hi James. Thank your for informing me this bug. I think I've fixed this bug with the following code:

func init() {
tmpProgname := strings.Split(gProgname, "") // for compatible with go run under Windows
gProgname = tmpProgname[len(tmpProgname)-1]
// ... ...
}

I'm sorry I don't have a Windows Environment for testing if it's actually fixed. Would you please kindly have a try and tell me if it's fixed?

@JamesCullum
Copy link
Author

Tested, it works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants