Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-log
Commits
4f346089
Unverified
Commit
4f346089
authored
Sep 04, 2020
by
Jakub Sztandera
Committed by
GitHub
Sep 04, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #101 from anytypeio/add-zap-url
Add an option to pass URL to zap
parents
0016c0b4
264b187b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
setup.go
setup.go
+13
-0
No files found.
setup.go
View file @
4f346089
...
...
@@ -30,6 +30,8 @@ const (
envLoggingFmt
=
"GOLOG_LOG_FMT"
envLoggingFile
=
"GOLOG_FILE"
// /path/to/file
envLoggingURL
=
"GOLOG_URL"
// url that will be processed by sink in the zap
envLoggingOutput
=
"GOLOG_OUTPUT"
// possible values: stdout|stderr|file combine multiple values with '+'
)
...
...
@@ -56,6 +58,9 @@ type Config struct {
// File is a path to a file that logs will be written to.
File
string
// URL with schema supported by zap. Use zap.RegisterSink
URL
string
}
// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
...
...
@@ -107,6 +112,9 @@ func SetupLogging(cfg Config) {
outputPaths
=
append
(
outputPaths
,
path
)
}
}
if
len
(
cfg
.
URL
)
>
0
{
outputPaths
=
append
(
outputPaths
,
cfg
.
URL
)
}
ws
,
_
,
err
:=
zap
.
Open
(
outputPaths
...
)
if
err
!=
nil
{
...
...
@@ -265,6 +273,7 @@ func configFromEnv() Config {
cfg
.
Stderr
=
false
}
cfg
.
URL
=
os
.
Getenv
(
envLoggingURL
)
output
:=
os
.
Getenv
(
envLoggingOutput
)
outputOptions
:=
strings
.
Split
(
output
,
"+"
)
for
_
,
opt
:=
range
outputOptions
{
...
...
@@ -277,6 +286,10 @@ func configFromEnv() Config {
if
cfg
.
File
==
""
{
fmt
.
Fprint
(
os
.
Stderr
,
"please specify a GOLOG_FILE value to write to"
)
}
case
"url"
:
if
cfg
.
URL
==
""
{
fmt
.
Fprint
(
os
.
Stderr
,
"please specify a GOLOG_URL value to write to"
)
}
}
}
...
...
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