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-unixfs
Commits
e7d71338
Commit
e7d71338
authored
Oct 17, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
colored logfmt
parent
1edc5a46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
util/log.go
util/log.go
+21
-4
No files found.
util/log.go
View file @
e7d71338
...
...
@@ -13,8 +13,19 @@ func init() {
var
log
=
Logger
(
"util"
)
// LogFormat is the format used for our logger.
var
LogFormat
=
"%{color}%{time:2006-01-02 15:04:05.999999} %{shortfile} %{level}: %{color:reset}%{message}"
var
ansiGray
=
"
\0
33[0;37m"
// LogFormats is a map of formats used for our logger, keyed by name.
var
LogFormats
=
map
[
string
]
string
{
"default"
:
"%{color}%{time:2006-01-02 15:04:05.999999} %{level} %{shortfile}: %{color:reset}%{message}"
,
"color"
:
ansiGray
+
"%{time:15:04:05.999} %{color}%{level} "
+
ansiGray
+
"%{shortfile}: %{color:reset}%{message}"
,
}
// Logging environment variables
const
(
envLogging
=
"IPFS_LOGGING"
envLoggingFmt
=
"IPFS_LOGGING_FMT"
)
// loggers is the set of loggers in the system
var
loggers
=
map
[
string
]
*
logging
.
Logger
{}
...
...
@@ -26,13 +37,19 @@ func POut(format string, a ...interface{}) {
// SetupLogging will initialize the logger backend and set the flags.
func
SetupLogging
()
{
fmt
:=
LogFormats
[
os
.
Getenv
(
envLoggingFmt
)]
if
fmt
==
""
{
fmt
=
LogFormats
[
"default"
]
}
backend
:=
logging
.
NewLogBackend
(
os
.
Stderr
,
""
,
0
)
logging
.
SetBackend
(
backend
)
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
LogForma
t
))
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
fm
t
))
lvl
:=
logging
.
ERROR
if
logenv
:=
os
.
Getenv
(
"IPFS_LOGGING"
);
logenv
!=
""
{
if
logenv
:=
os
.
Getenv
(
envLogging
);
logenv
!=
""
{
var
err
error
lvl
,
err
=
logging
.
LogLevel
(
logenv
)
if
err
!=
nil
{
...
...
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