Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
ca3e8301
提交
ca3e8301
authored
11月 24, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #380 from jbenet/fix/eventlog-init-condition
fix(eventlog) initialization
上级
6c94a071
90ed1482
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
57 行增加
和
28 行删除
+57
-28
init.go
cmd/ipfs/init.go
+11
-5
main.go
cmd/ipfs/main.go
+3
-23
logs.go
repo/logs.go
+28
-0
repo.go
repo/repo.go
+15
-0
没有找到文件。
cmd/ipfs/init.go
浏览文件 @
ca3e8301
...
...
@@ -16,7 +16,8 @@ import (
chunk
"github.com/jbenet/go-ipfs/importer/chunk"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util/debugerror"
debugerror
"github.com/jbenet/go-ipfs/util/debugerror"
repo
"github.com/jbenet/go-ipfs/repo"
)
const
nBitsForKeypairDefault
=
4096
...
...
@@ -251,6 +252,8 @@ func identityConfig(nbits int) (config.Identity, error) {
return
ident
,
nil
}
// initLogs initializes the event logger at the specified path. It uses the
// default log path if no path is provided.
func
initLogs
(
logpath
string
)
(
config
.
Logs
,
error
)
{
if
len
(
logpath
)
==
0
{
var
err
error
...
...
@@ -259,15 +262,18 @@ func initLogs(logpath string) (config.Logs, error) {
return
config
.
Logs
{},
debugerror
.
Wrap
(
err
)
}
}
err
:=
initCheckDir
(
logpath
)
if
err
!=
nil
{
return
config
.
Logs
{},
debugerror
.
Errorf
(
"logs: %s"
,
err
)
}
return
config
.
Logs
{
conf
:=
config
.
Logs
{
Filename
:
path
.
Join
(
logpath
,
"events.log"
),
},
nil
}
err
=
repo
.
ConfigureEventLogger
(
conf
)
if
err
!=
nil
{
return
conf
,
err
}
return
conf
,
nil
}
// initCheckDir ensures the directory exists and is writable
...
...
cmd/ipfs/main.go
浏览文件 @
ca3e8301
...
...
@@ -24,6 +24,7 @@ import (
u
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util/debugerror"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
repo
"github.com/jbenet/go-ipfs/repo"
)
// log is the command logger
...
...
@@ -271,13 +272,13 @@ func callPreCommandHooks(details cmdDetails, req cmds.Request, root *cmds.Comman
// When the upcoming command may use the config and repo, we know it's safe
// for the log config hook to touch the config/repo
if
details
.
usesConfigAsInput
()
&&
details
.
usesRepo
(
)
{
if
repo
.
IsInitialized
(
req
.
Context
()
.
ConfigRoot
)
{
log
.
Debug
(
"Calling hook: Configure Event Logger"
)
cfg
,
err
:=
req
.
Context
()
.
GetConfig
()
if
err
!=
nil
{
return
err
}
configureEventLogger
(
cfg
)
repo
.
ConfigureEventLogger
(
cfg
.
Logs
)
}
return
nil
...
...
@@ -509,24 +510,3 @@ func allInterruptSignals() chan os.Signal {
syscall
.
SIGTERM
,
syscall
.
SIGQUIT
)
return
sigc
}
func
configureEventLogger
(
config
*
config
.
Config
)
error
{
if
u
.
Debug
{
eventlog
.
Configure
(
eventlog
.
LevelDebug
)
}
else
{
eventlog
.
Configure
(
eventlog
.
LevelInfo
)
}
eventlog
.
Configure
(
eventlog
.
LdJSONFormatter
)
rotateConf
:=
eventlog
.
LogRotatorConfig
{
Filename
:
config
.
Logs
.
Filename
,
MaxSizeMB
:
config
.
Logs
.
MaxSizeMB
,
MaxBackups
:
config
.
Logs
.
MaxBackups
,
MaxAgeDays
:
config
.
Logs
.
MaxAgeDays
,
}
eventlog
.
Configure
(
eventlog
.
OutputRotatingLogFile
(
rotateConf
))
return
nil
}
repo/logs.go
0 → 100644
浏览文件 @
ca3e8301
package
repo
import
(
util
"github.com/jbenet/go-ipfs/util"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
config
"github.com/jbenet/go-ipfs/config"
)
func
ConfigureEventLogger
(
config
config
.
Logs
)
error
{
if
util
.
Debug
{
eventlog
.
Configure
(
eventlog
.
LevelDebug
)
}
else
{
eventlog
.
Configure
(
eventlog
.
LevelInfo
)
}
eventlog
.
Configure
(
eventlog
.
LdJSONFormatter
)
rotateConf
:=
eventlog
.
LogRotatorConfig
{
Filename
:
config
.
Filename
,
MaxSizeMB
:
config
.
MaxSizeMB
,
MaxBackups
:
config
.
MaxBackups
,
MaxAgeDays
:
config
.
MaxAgeDays
,
}
eventlog
.
Configure
(
eventlog
.
OutputRotatingLogFile
(
rotateConf
))
return
nil
}
repo/repo.go
0 → 100644
浏览文件 @
ca3e8301
package
repo
import
util
"github.com/jbenet/go-ipfs/util"
// IsInitialized returns true if the path is home to an initialized IPFS
// repository.
func
IsInitialized
(
path
string
)
bool
{
if
!
util
.
FileExists
(
path
)
{
return
false
}
// TODO add logging check
// TODO add datastore check
// TODO add config file check
return
true
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论