Init configuration from file #3
No reviewers
Labels
No Label
in progress
kind/breaking
kind/bug
kind/deployment
kind/docs
kind/enhancement
kind/feature
kind/lint
kind/proposal
kind/question
kind/security
kind/testing
kind/translation
kind/ui
lgtm/done
lgtm/need
lgtm/need
priority/critical
priority/low
priority/maybe
priority/medium
refactor
reviewed/duplicate
reviewed/invalid
reviewed/wontfix
status/blocked
status/needs-feedback
status/wip
No Milestone
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: gitea/log#3
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "zeripath/log:nicer-configuration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR provides a way of configuring the loggers independently from the program.
The main benefit is that logging can be set for unit tests
OK so an example test program looking like:
with configuration:
works and changes the log configuration.
Now the reason for doing config in init is that unit tests in go are quite annoying - they don't have an easy way of doing set-up consistently without requiring a TestMain for each package.
If we allow our configuration to occur in init we can always pass log configuration in to any test.
One final issue is the requirement to add a
defer log.Close()
to ensure that the final logs are written. I'll look at this. - Looks like there is no other way.Maybe we can call
runtime.SetFinalizer(obj, func(obj *typeObj))
to insteaddefer log.Close
.hmm... so that looked like good idea but it's neither guaranteed to run on
os.Exit(...)
nor is it guaranteed to run for objects allocated ininit()
.I think we just have to tolerate that people should add a
defer log.Close()
tomain()
and suggestdefer log.Flush()
added to unit tests.Please resolve the conflicts
Done.
@ -173,3 +200,3 @@
}
// Close closes all the loggers
// Close closes the default logger
Why not all the loggers?
Sorry missed changing that comment. Done now.
@ -230,2 +280,4 @@
}
// create a default log to write to console
NewLogger(1000, "std", "console", fmt.Sprintf(`{"flags":%d, "stacktraceLevel":"error"}`,
If config load successfully, the default logger should be disabled I think.
Take a look at line 278:
if there's no error during configuration from the provided configuration then
init()
returns here.OK. Just found we need add reactions on code comments.