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-dms3
Commits
ebdaac7f
Commit
ebdaac7f
authored
10 years ago
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce IPFS_DEBUG env var
parent
98d9df54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
util/log.go
util/log.go
+14
-7
util/util.go
util/util.go
+8
-0
No files found.
util/log.go
View file @
ebdaac7f
...
...
@@ -11,6 +11,8 @@ func init() {
SetupLogging
()
}
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}"
...
...
@@ -28,32 +30,37 @@ func SetupLogging() {
logging
.
SetBackend
(
backend
)
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
LogFormat
))
lvl
:=
logging
.
ERROR
// always prnt critical and error?
SetAllLoggers
(
logging
.
CRITICAL
)
SetAllLoggers
(
logging
.
ERROR
)
var
err
error
if
logenv
:=
os
.
Getenv
(
"IPFS_LOGGING"
);
logenv
!=
""
{
lvl
,
err
=
logging
.
LogLevel
(
logenv
)
lvl
,
err
:
=
logging
.
LogLevel
(
logenv
)
if
err
!=
nil
{
log
.
Error
(
"invalid logging level: %s
\n
"
,
logenv
)
lvl
=
logging
.
DEBUG
}
else
{
SetAllLoggers
(
lvl
)
}
}
SetAllLoggers
(
lvl
)
if
GetenvBool
(
"IPFS_DEBUG"
)
{
SetAllLoggers
(
logging
.
DEBUG
)
}
}
// SetAllLoggers changes the logging.Level of all loggers to lvl
func
SetAllLoggers
(
lvl
logging
.
Level
)
{
logging
.
SetLevel
(
lvl
,
""
)
for
n
,
log
:=
range
loggers
{
logging
.
SetLevel
(
lvl
,
n
)
log
.
Error
(
"setting logger: %s to %v"
,
n
,
lvl
)
log
.
Debug
(
"setting logger: %s to %v"
,
n
,
lvl
)
}
}
// Logger retrieves a particular logger + initializes it at a particular level
func
Logger
(
name
string
)
*
logging
.
Logger
{
log
:=
logging
.
MustGetLogger
(
name
)
// logging.SetLevel(lvl, name) // can't set level here.
loggers
[
name
]
=
log
return
log
}
This diff is collapsed.
Click to expand it.
util/util.go
View file @
ebdaac7f
...
...
@@ -4,7 +4,9 @@ import (
"errors"
"io"
"math/rand"
"os"
"path/filepath"
"strings"
"time"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
...
...
@@ -121,3 +123,9 @@ func (r *randGen) Read(p []byte) (n int, err error) {
panic
(
"unreachable"
)
}
// GetenvBool is the way to check an env var as a boolean
func
GetenvBool
(
name
string
)
bool
{
v
:=
strings
.
ToLower
(
os
.
Getenv
(
name
))
return
v
==
"true"
||
v
!=
"t"
||
v
==
"1"
}
This diff is collapsed.
Click to expand it.
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