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
aa79f385
Commit
aa79f385
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup logging setup.
- should not be on init, because need debug flag
parent
ba510cbd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
26 deletions
+38
-26
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+22
-13
cmd/ipfs/publish.go
cmd/ipfs/publish.go
+0
-1
cmd/ipfs/resolve.go
cmd/ipfs/resolve.go
+0
-1
cmd/ipfs/run.go
cmd/ipfs/run.go
+0
-3
util/util.go
util/util.go
+16
-8
No files found.
cmd/ipfs/ipfs.go
View file @
aa79f385
...
...
@@ -6,9 +6,10 @@ import (
"os"
"runtime/pprof"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/config"
flag
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
commander
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
config
"github.com/jbenet/go-ipfs/config"
core
"github.com/jbenet/go-ipfs/core"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -72,7 +73,13 @@ func ipfsCmd(c *commander.Command, args []string) error {
}
func
main
()
{
u
.
Debug
=
true
u
.
Debug
=
false
// setup logging
u
.
SetupLogging
()
// if debugging, setup profiling.
if
u
.
Debug
{
ofi
,
err
:=
os
.
Create
(
"cpu.prof"
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
...
...
@@ -81,7 +88,9 @@ func main() {
pprof
.
StartCPUProfile
(
ofi
)
defer
ofi
.
Close
()
defer
pprof
.
StopCPUProfile
()
err
=
CmdIpfs
.
Dispatch
(
os
.
Args
[
1
:
])
}
err
:=
CmdIpfs
.
Dispatch
(
os
.
Args
[
1
:
])
if
err
!=
nil
{
if
len
(
err
.
Error
())
>
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ipfs %s: %v
\n
"
,
os
.
Args
[
1
],
err
)
...
...
@@ -114,7 +123,7 @@ func getConfigDir(c *commander.Command) (string, error) {
}
confStr
,
ok
:=
conf
.
(
string
)
if
!
ok
{
return
""
,
errors
.
New
(
"failed to retrieve config flag value
.
"
)
return
""
,
errors
.
New
(
"failed to retrieve config flag value"
)
}
if
len
(
confStr
)
==
0
{
return
config
.
PathRoot
()
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs/publish.go
View file @
aa79f385
...
...
@@ -25,7 +25,6 @@ func init() {
}
func
pubCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
u
.
Debug
=
true
if
len
(
inp
)
<
1
{
u
.
POut
(
c
.
Long
)
return
nil
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs/resolve.go
View file @
aa79f385
...
...
@@ -23,7 +23,6 @@ var cmdIpfsResolve = &commander.Command{
}
func
resolveCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
u
.
Debug
=
true
if
len
(
inp
)
<
1
{
u
.
POut
(
c
.
Long
)
return
nil
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs/run.go
View file @
aa79f385
...
...
@@ -7,7 +7,6 @@ import (
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
"github.com/jbenet/go-ipfs/daemon"
u
"github.com/jbenet/go-ipfs/util"
)
var
cmdIpfsRun
=
&
commander
.
Command
{
...
...
@@ -20,8 +19,6 @@ var cmdIpfsRun = &commander.Command{
}
func
runCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
u
.
Debug
=
true
conf
,
err
:=
getConfigDir
(
c
.
Parent
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
util/util.go
View file @
aa79f385
...
...
@@ -11,16 +11,11 @@ import (
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
logging
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
)
var
format
=
"%{color}%{time:01-02 15:04:05.9999} %{shortfile} %{level}: %{color:reset}%{message}"
func
init
()
{
backend
:=
logging
.
NewLogBackend
(
os
.
Stderr
,
""
,
0
)
logging
.
SetBackend
(
backend
)
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
format
))
}
// LogFormat is the format used for our logger.
var
LogFormat
=
"%{color}%{time:01-02 15:04:05.9999} %{shortfile} %{level}: %{color:reset}%{message}"
// Debug is a global flag for debugging.
var
Debug
bool
...
...
@@ -51,6 +46,7 @@ func Hash(data []byte) (mh.Multihash, error) {
return
mh
.
Sum
(
data
,
mh
.
SHA2_256
,
-
1
)
}
// IsValidHash checks whether a given hash is valid (b58 decodable, len > 0)
func
IsValidHash
(
s
string
)
bool
{
out
:=
b58
.
Decode
(
s
)
if
out
==
nil
||
len
(
out
)
==
0
{
...
...
@@ -99,6 +95,18 @@ func DOut(format string, a ...interface{}) {
}
}
// SetupLogging will initialize the logger backend and set the flags.
func
SetupLogging
()
{
backend
:=
logging
.
NewLogBackend
(
os
.
Stderr
,
""
,
0
)
logging
.
SetBackend
(
backend
)
if
Debug
{
logging
.
SetLevel
(
logging
.
DEBUG
,
""
)
}
else
{
logging
.
SetLevel
(
logging
.
ERROR
,
""
)
}
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
LogFormat
))
}
// ExpandPathnames takes a set of paths and turns them into absolute paths
func
ExpandPathnames
(
paths
[]
string
)
([]
string
,
error
)
{
var
out
[]
string
...
...
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