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

FLAGS=none has no effect on log flags #8856

Closed
2 of 7 tasks
samangh opened this issue Nov 6, 2019 · 1 comment · Fixed by #9287
Closed
2 of 7 tasks

FLAGS=none has no effect on log flags #8856

samangh opened this issue Nov 6, 2019 · 1 comment · Fixed by #9287
Labels

Comments

@samangh
Copy link

samangh commented Nov 6, 2019

  • Gitea version (or commit ref): 1.9.5 built with GNU Make 4.1, go1.12.11 : bindata, sqlite, sqlite_unlock_notify
  • Operating system: Debian Stable
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

I'm trying to prevent gitea from adding data/time/etc log flags to its console output. This is becuase the console output is automatically sent to syslog when using systemd to start gitea, and syslog adds its own date/time stamps.

This should be doable by setting log.console.FLAGS to none according to the config cheat sheet. However, setting log.console.FLAGS to none as no effect and console logs are still shown with the default stdflags stuff. Setting log.console.FLAGS to other values seem to work though (for example level or date work as expected).

Relevant config:

[log]
MODE      = console,file
ROOT_PATH = /home/git/gitea/log
COLORIZE  = false

; Put all router-related suff in files
ROUTER   = file
REDIRECT_MACARON_LOG = true

[log.console]
; When using systemd, the console output is sent to syslog.  So we
; don't need the data, time, etc as that is already in syslog.
FLAGS = "none"

Example output on syslog:

Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...dules/setting/log.go:269:newLogService() [I] Gitea Log Mode: Console(Console:info)
Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...dules/setting/log.go:269:newLogService() [I] Gitea Log Mode: File(File:info)
Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...dules/setting/log.go:178:generateNamedLogger() [I] Macaron Log: File(file:info)
Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...dules/setting/log.go:178:generateNamedLogger() [I] Router Log: File(file:info)
Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...les/setting/cache.go:42:newCacheService() [I] Cache Service Enabled
Nov  5 17:06:04 server gitea[8484]: 2019/11/05 17:06:04 ...s/setting/session.go:45:newSessionService() [I] Session Service Enabled
@zeripath
Copy link
Contributor

zeripath commented Nov 6, 2019

Damn. The problem lies here:

// FlagsFromString takes a comma separated list of flags and returns
// the flags for this string
func FlagsFromString(from string) int {
flags := 0
for _, flag := range strings.Split(strings.ToLower(from), ",") {
f, ok := flagFromString[strings.TrimSpace(flag)]
if ok {
flags |= f
}
}
return flags
}

Which interacts with lines 44-46 here:

// NewWriterLogger creates a new WriterLogger from the provided WriteCloser.
// Optionally the level can be changed at the same time.
func (logger *WriterLogger) NewWriterLogger(out io.WriteCloser, level ...Level) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.out = out
switch logger.Flags {
case 0:
logger.Flags = LstdFlags
case -1:
logger.Flags = 0
}
if len(level) > 0 {
logger.Level = level[0]
}
logger.createExpression()
}

Flags should be returned as -1 if none.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants