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

Remove the default console logger when it is not set in the configuration #602

Merged
merged 5 commits into from
Jan 17, 2017

Conversation

willemvd
Copy link
Contributor

@willemvd willemvd commented Jan 6, 2017

Fix for issue #581
Removes the default console logger when it is not set in the configuration

Mark: this is my first Go programming experience so please be gentle ;)

@@ -867,6 +867,16 @@ func newLogService() {
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
LogConfigs = make([]string, len(LogModes))

useConsole := false;
for _, mode := range LogModes {
if "console" == mode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode == "console"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this "safer" or just a code style ? in Java (yes that is why there are ; every where 😄 ) the "console".equals(mode) is null safe

still followed your proposal

Copy link
Member

@appleboy appleboy Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't set variable as a value in if condition.

package main

import "fmt"

func main() {
	a := 1
	if a = 1 {
		fmt.Println("a=1")
	}
}

It is not readable for value == variable

@@ -867,6 +867,16 @@ func newLogService() {
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
LogConfigs = make([]string, len(LogModes))

useConsole := false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ;

useConsole := false;
for _, mode := range LogModes {
if "console" == mode {
useConsole = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ;

}
if (!useConsole) {
log.DelLogger("console");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !useConsole {
  log.DelLogger("console")
}

@lunny lunny added this to the 1.1.0 milestone Jan 6, 2017
@lunny lunny added the type/bug label Jan 6, 2017
@bkcsoft
Copy link
Member

bkcsoft commented Jan 6, 2017

Have you tried that it works, both with and without console enabled? :)

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 6, 2017
return l.DelLogger(mode)
}
}
panic("log: unknown adapter \"" + mode + "\" (forgotten register?)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly cleaner :)

panic(`log: unknown adapter "` + mode + `" (forgotten register?)`)

@willemvd
Copy link
Contributor Author

willemvd commented Jan 6, 2017

yes tested it with and without console enabled

}
}
if (!useConsole) {
log.DelLogger("console")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this implementation, we always add the console logger (setting.go: line 421), and then sometimes remove it later (this if statement). Would it make more sense to check whether we need the console logger when we initially add it, instead of checking after we've already added it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct, was thinking about setting the log level earlier but then you could miss some information about where the custom log file is read from
So that is why I have decided to do it this way

…nstead of adapter, otherwise panic when reinstalling gitea (since the output adapter still exist, without outputs)
@tboerger
Copy link
Member

LGTM for now

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 16, 2017
@appleboy
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 17, 2017
@lunny lunny merged commit 8c2c7b8 into go-gitea:master Jan 17, 2017
@lunny
Copy link
Member

lunny commented Jan 26, 2017

@willemvd This could be back port to v1.0.

lunny pushed a commit to lunny/gitea that referenced this pull request Feb 16, 2017
…tion (go-gitea#602)

* Remove the default console logger when it is not set in the configuration

* Added comment to new function (lint failure)

* update based on PR comments (code style)

* code style fix (thanks bkcsoft)

* check if logger exists based on the l.outputs (like in l.DelLogger) instead of adapter, otherwise panic when reinstalling gitea (since the output adapter still exist, without outputs)
lunny added a commit that referenced this pull request Feb 18, 2017
…tion (#602) (#960)

* Remove the default console logger when it is not set in the configuration

* Added comment to new function (lint failure)

* update based on PR comments (code style)

* code style fix (thanks bkcsoft)

* check if logger exists based on the l.outputs (like in l.DelLogger) instead of adapter, otherwise panic when reinstalling gitea (since the output adapter still exist, without outputs)
@lunny lunny added the backport/done All backports for this PR have been created label Feb 18, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants