Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
9ef6b2c8
Commit
9ef6b2c8
authored
Jul 13, 2018
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add structured logFormat for text based logging
parent
1395dc01
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
logging.go
logging.go
+8
-3
main.go
main.go
+1
-1
No files found.
logging.go
View file @
9ef6b2c8
...
@@ -36,6 +36,7 @@ func prepareLoggingFile(logFile string) *reopen.FileWriter {
...
@@ -36,6 +36,7 @@ func prepareLoggingFile(logFile string) *reopen.FileWriter {
const
(
const
(
jsonLogFormat
=
"json"
jsonLogFormat
=
"json"
textLogFormat
=
"text"
textLogFormat
=
"text"
structuredFormat
=
"structured"
noneLogType
=
"none"
noneLogType
=
"none"
)
)
...
@@ -69,6 +70,10 @@ func startLogging(config logConfiguration) {
...
@@ -69,6 +70,10 @@ func startLogging(config logConfiguration) {
accessLogEntry
=
accessLogger
.
WithField
(
"system"
,
"http"
)
accessLogEntry
=
accessLogger
.
WithField
(
"system"
,
"http"
)
log
.
SetFormatter
(
&
log
.
TextFormatter
{})
log
.
SetFormatter
(
&
log
.
TextFormatter
{})
case
structuredFormat
:
formatter
:=
&
log
.
TextFormatter
{
ForceColors
:
true
,
EnvironmentOverrideColors
:
true
}
log
.
SetFormatter
(
formatter
)
accessLogEntry
=
log
.
WithField
(
"system"
,
"http"
)
default
:
default
:
log
.
WithField
(
"logFormat"
,
config
.
logFormat
)
.
Fatal
(
"Unknown logFormat configured"
)
log
.
WithField
(
"logFormat"
,
config
.
logFormat
)
.
Fatal
(
"Unknown logFormat configured"
)
}
}
...
...
main.go
View file @
9ef6b2c8
...
@@ -59,7 +59,7 @@ var logConfig = logConfiguration{}
...
@@ -59,7 +59,7 @@ var logConfig = logConfiguration{}
func
init
()
{
func
init
()
{
flag
.
StringVar
(
&
logConfig
.
logFile
,
"logFile"
,
""
,
"Log file location"
)
flag
.
StringVar
(
&
logConfig
.
logFile
,
"logFile"
,
""
,
"Log file location"
)
flag
.
StringVar
(
&
logConfig
.
logFormat
,
"logFormat"
,
"text"
,
"Log format to use defaults to text (text, json, none)"
)
flag
.
StringVar
(
&
logConfig
.
logFormat
,
"logFormat"
,
"text"
,
"Log format to use defaults to text (text, json,
structured,
none)"
)
}
}
func
main
()
{
func
main
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment