Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
90896f28
提交
90896f28
authored
6月 17, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up unused log options
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
a676b5a8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
6 行增加
和
508 行删除
+6
-508
Godeps.json
Godeps/Godeps.json
+1
-5
.gitignore
...workspace/src/gopkg.in/natefinch/lumberjack.v2/.gitignore
+0
-23
LICENSE
...s/_workspace/src/gopkg.in/natefinch/lumberjack.v2/LICENSE
+0
-22
README.md
..._workspace/src/gopkg.in/natefinch/lumberjack.v2/README.md
+0
-166
chown.go
.../_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown.go
+0
-11
chown_linux.go
...space/src/gopkg.in/natefinch/lumberjack.v2/chown_linux.go
+0
-19
example_test.go
...pace/src/gopkg.in/natefinch/lumberjack.v2/example_test.go
+0
-18
linux_test.go
...kspace/src/gopkg.in/natefinch/lumberjack.v2/linux_test.go
+0
-104
lumberjack.go
...kspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack.go
+0
-0
lumberjack_test.go
...e/src/gopkg.in/natefinch/lumberjack.v2/lumberjack_test.go
+0
-0
rotate_test.go
...space/src/gopkg.in/natefinch/lumberjack.v2/rotate_test.go
+0
-27
testing_test.go
...pace/src/gopkg.in/natefinch/lumberjack.v2/testing_test.go
+0
-91
logs.go
core/corehttp/logs.go
+4
-1
option.go
thirdparty/eventlog/option.go
+1
-21
没有找到文件。
Godeps/Godeps.json
浏览文件 @
90896f28
...
...
@@ -269,11 +269,6 @@
"Rev"
:
"96c060f6a6b7e0d6f75fddd10efeaca3e5d1bcb0"
},
{
"ImportPath"
:
"gopkg.in/natefinch/lumberjack.v2"
,
"Comment"
:
"v1.0-12-gd28785c"
,
"Rev"
:
"d28785c2f27cd682d872df46ccd8232843629f54"
},
{
"ImportPath"
:
"gopkg.in/tomb.v1"
,
"Rev"
:
"dd632973f1e7218eb1089048e0798ec9ae7dceb8"
},
...
...
@@ -281,5 +276,6 @@
"ImportPath"
:
"github.com/chriscool/go-sleep"
,
"Rev"
:
"743ab5f1bb487edf1772bc29ca0bdf572b40785e"
}
]
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/.gitignore
deleted
100644 → 0
浏览文件 @
a676b5a8
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/LICENSE
deleted
100644 → 0
浏览文件 @
a676b5a8
The MIT License (MIT)
Copyright (c) 2014 Nate Finch
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/README.md
deleted
100644 → 0
浏览文件 @
a676b5a8
# lumberjack [](https://godoc.org/gopkg.in/natefinch/lumberjack.v2) [](https://drone.io/github.com/natefinch/lumberjack/latest) [](https://ci.appveyor.com/project/natefinch/lumberjack)
### Lumberjack is a Go package for writing logs to rolling files.
Package lumberjack provides a rolling logger.
Note that this is v2.0 of lumberjack, and should be imported using gopkg.in
thusly:
import "gopkg.in/natefinch/lumberjack.v2"
The package name remains simply lumberjack, and the code resides at
https://github.com/natefinch/lumberjack under the v2.0 branch.
Lumberjack is intended to be one part of a logging infrastructure.
It is not an all-in-one solution, but instead is a pluggable
component at the bottom of the logging stack that simply controls the files
to which logs are written.
Lumberjack plays well with any logging package that can write to an
io.Writer, including the standard library's log package.
Lumberjack assumes that only one process is writing to the output files.
Using the same lumberjack configuration from multiple processes on the same
machine will result in improper behavior.
**Example**
To use lumberjack with the standard library's log package, just pass it into the SetOutput function when your application starts.
Code:
```
go
log
.
SetOutput
(
&
lumberjack
.
Logger
{
Filename
:
"/var/log/myapp/foo.log"
,
MaxSize
:
500
,
// megabytes
MaxBackups
:
3
,
MaxAge
:
28
,
//days
})
```
## type Logger
```
go
type
Logger
struct
{
// Filename is the file to write logs to. Backup log files will be retained
// in the same directory. It uses <processname>-lumberjack.log in
// os.TempDir() if empty.
Filename
string
`json:"filename" yaml:"filename"`
// MaxSize is the maximum size in megabytes of the log file before it gets
// rotated. It defaults to 100 megabytes.
MaxSize
int
`json:"maxsize" yaml:"maxsize"`
// MaxAge is the maximum number of days to retain old log files based on the
// timestamp encoded in their filename. Note that a day is defined as 24
// hours and may not exactly correspond to calendar days due to daylight
// savings, leap seconds, etc. The default is not to remove old log files
// based on age.
MaxAge
int
`json:"maxage" yaml:"maxage"`
// MaxBackups is the maximum number of old log files to retain. The default
// is to retain all old log files (though MaxAge may still cause them to get
// deleted.)
MaxBackups
int
`json:"maxbackups" yaml:"maxbackups"`
// LocalTime determines if the time used for formatting the timestamps in
// backup files is the computer's local time. The default is to use UTC
// time.
LocalTime
bool
`json:"localtime" yaml:"localtime"`
// contains filtered or unexported fields
}
```
Logger is an io.WriteCloser that writes to the specified filename.
Logger opens or creates the logfile on first Write. If the file exists and
is less than MaxSize megabytes, lumberjack will open and append to that file.
If the file exists and its size is >= MaxSize megabytes, the file is renamed
by putting the current time in a timestamp in the name immediately before the
file's extension (or the end of the filename if there's no extension). A new
log file is then created using original filename.
Whenever a write would cause the current log file exceed MaxSize megabytes,
the current file is closed, renamed, and a new log file created with the
original name. Thus, the filename you give Logger is always the "current" log
file.
### Cleaning Up Old Log Files
Whenever a new logfile gets created, old log files may be deleted. The most
recent files according to the encoded timestamp will be retained, up to a
number equal to MaxBackups (or all of them if MaxBackups is 0). Any files
with an encoded timestamp older than MaxAge days are deleted, regardless of
MaxBackups. Note that the time encoded in the timestamp is the rotation
time, which may differ from the last time that file was written to.
If MaxBackups and MaxAge are both 0, no old log files will be deleted.
### func (\*Logger) Close
```
go
func
(
l
*
Logger
)
Close
()
error
```
Close implements io.Closer, and closes the current logfile.
### func (\*Logger) Rotate
```
go
func
(
l
*
Logger
)
Rotate
()
error
```
Rotate causes Logger to close the existing log file and immediately create a
new one. This is a helper function for applications that want to initiate
rotations outside of the normal rotation rules, such as in response to
SIGHUP. After rotating, this initiates a cleanup of old log files according
to the normal rules.
**Example**
Example of how to rotate in response to SIGHUP.
Code:
```
go
l
:=
&
lumberjack
.
Logger
{}
log
.
SetOutput
(
l
)
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
syscall
.
SIGHUP
)
go
func
()
{
for
{
<-
c
l
.
Rotate
()
}
}()
```
### func (\*Logger) Write
```
go
func
(
l
*
Logger
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
```
Write implements io.Writer. If a write would cause the log file to be larger
than MaxSize, the file is closed, renamed to include a timestamp of the
current time, and a new log file is created using the original log file name.
If the length of the write is greater than MaxSize, an error is returned.
- - -
Generated by
[
godoc2md
](
http://godoc.org/github.com/davecheney/godoc2md
)
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown.go
deleted
100644 → 0
浏览文件 @
a676b5a8
// +build !linux
package
lumberjack
import
(
"os"
)
func
chown
(
_
string
,
_
os
.
FileInfo
)
error
{
return
nil
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/chown_linux.go
deleted
100644 → 0
浏览文件 @
a676b5a8
package
lumberjack
import
(
"os"
"syscall"
)
// os_Chown is a var so we can mock it out during tests.
var
os_Chown
=
os
.
Chown
func
chown
(
name
string
,
info
os
.
FileInfo
)
error
{
f
,
err
:=
os
.
OpenFile
(
name
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_TRUNC
,
info
.
Mode
())
if
err
!=
nil
{
return
err
}
f
.
Close
()
stat
:=
info
.
Sys
()
.
(
*
syscall
.
Stat_t
)
return
os_Chown
(
name
,
int
(
stat
.
Uid
),
int
(
stat
.
Gid
))
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/example_test.go
deleted
100644 → 0
浏览文件 @
a676b5a8
package
lumberjack_test
import
(
"log"
"github.com/natefinch/lumberjack"
)
// To use lumberjack with the standard library's log package, just pass it into
// the SetOutput function when your application starts.
func
Example
()
{
log
.
SetOutput
(
&
lumberjack
.
Logger
{
Filename
:
"/var/log/myapp/foo.log"
,
MaxSize
:
500
,
// megabytes
MaxBackups
:
3
,
MaxAge
:
28
,
// days
})
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/linux_test.go
deleted
100644 → 0
浏览文件 @
a676b5a8
// +build linux
package
lumberjack
import
(
"os"
"syscall"
"testing"
)
func
TestMaintainMode
(
t
*
testing
.
T
)
{
currentTime
=
fakeTime
dir
:=
makeTempDir
(
"TestMaintainMode"
,
t
)
defer
os
.
RemoveAll
(
dir
)
filename
:=
logFile
(
dir
)
mode
:=
os
.
FileMode
(
0770
)
f
,
err
:=
os
.
OpenFile
(
filename
,
os
.
O_CREATE
|
os
.
O_RDWR
,
mode
)
isNil
(
err
,
t
)
f
.
Close
()
l
:=
&
Logger
{
Filename
:
filename
,
MaxBackups
:
1
,
MaxSize
:
100
,
// megabytes
}
defer
l
.
Close
()
b
:=
[]
byte
(
"boo!"
)
n
,
err
:=
l
.
Write
(
b
)
isNil
(
err
,
t
)
equals
(
len
(
b
),
n
,
t
)
newFakeTime
()
err
=
l
.
Rotate
()
isNil
(
err
,
t
)
filename2
:=
backupFile
(
dir
)
info
,
err
:=
os
.
Stat
(
filename
)
isNil
(
err
,
t
)
info2
,
err
:=
os
.
Stat
(
filename2
)
isNil
(
err
,
t
)
equals
(
mode
,
info
.
Mode
(),
t
)
equals
(
mode
,
info2
.
Mode
(),
t
)
}
func
TestMaintainOwner
(
t
*
testing
.
T
)
{
fakeC
:=
fakeChown
{}
os_Chown
=
fakeC
.
Set
os_Stat
=
fakeStat
defer
func
()
{
os_Chown
=
os
.
Chown
os_Stat
=
os
.
Stat
}()
currentTime
=
fakeTime
dir
:=
makeTempDir
(
"TestMaintainOwner"
,
t
)
defer
os
.
RemoveAll
(
dir
)
filename
:=
logFile
(
dir
)
l
:=
&
Logger
{
Filename
:
filename
,
MaxBackups
:
1
,
MaxSize
:
100
,
// megabytes
}
defer
l
.
Close
()
b
:=
[]
byte
(
"boo!"
)
n
,
err
:=
l
.
Write
(
b
)
isNil
(
err
,
t
)
equals
(
len
(
b
),
n
,
t
)
newFakeTime
()
err
=
l
.
Rotate
()
isNil
(
err
,
t
)
equals
(
555
,
fakeC
.
uid
,
t
)
equals
(
666
,
fakeC
.
gid
,
t
)
}
type
fakeChown
struct
{
name
string
uid
int
gid
int
}
func
(
f
*
fakeChown
)
Set
(
name
string
,
uid
,
gid
int
)
error
{
f
.
name
=
name
f
.
uid
=
uid
f
.
gid
=
gid
return
nil
}
func
fakeStat
(
name
string
)
(
os
.
FileInfo
,
error
)
{
info
,
err
:=
os
.
Stat
(
name
)
if
err
!=
nil
{
return
info
,
err
}
stat
:=
info
.
Sys
()
.
(
*
syscall
.
Stat_t
)
stat
.
Uid
=
555
stat
.
Gid
=
666
return
info
,
nil
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack.go
deleted
100644 → 0
浏览文件 @
a676b5a8
差异被折叠。
点击展开。
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/lumberjack_test.go
deleted
100644 → 0
浏览文件 @
a676b5a8
差异被折叠。
点击展开。
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/rotate_test.go
deleted
100644 → 0
浏览文件 @
a676b5a8
// +build linux
package
lumberjack_test
import
(
"log"
"os"
"os/signal"
"syscall"
"github.com/natefinch/lumberjack"
)
// Example of how to rotate in response to SIGHUP.
func
ExampleLogger_Rotate
()
{
l
:=
&
lumberjack
.
Logger
{}
log
.
SetOutput
(
l
)
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
syscall
.
SIGHUP
)
go
func
()
{
for
{
<-
c
l
.
Rotate
()
}
}()
}
Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2/testing_test.go
deleted
100644 → 0
浏览文件 @
a676b5a8
package
lumberjack
import
(
"fmt"
"path/filepath"
"reflect"
"runtime"
"testing"
)
// assert will log the given message if condition is false.
func
assert
(
condition
bool
,
t
testing
.
TB
,
msg
string
,
v
...
interface
{})
{
assertUp
(
condition
,
t
,
1
,
msg
,
v
...
)
}
// assertUp is like assert, but used inside helper functions, to ensure that
// the file and line number reported by failures corresponds to one or more
// levels up the stack.
func
assertUp
(
condition
bool
,
t
testing
.
TB
,
caller
int
,
msg
string
,
v
...
interface
{})
{
if
!
condition
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
caller
+
1
)
v
=
append
([]
interface
{}{
filepath
.
Base
(
file
),
line
},
v
...
)
fmt
.
Printf
(
"%s:%d: "
+
msg
+
"
\n
"
,
v
...
)
t
.
FailNow
()
}
}
// equals tests that the two values are equal according to reflect.DeepEqual.
func
equals
(
exp
,
act
interface
{},
t
testing
.
TB
)
{
equalsUp
(
exp
,
act
,
t
,
1
)
}
// equalsUp is like equals, but used inside helper functions, to ensure that the
// file and line number reported by failures corresponds to one or more levels
// up the stack.
func
equalsUp
(
exp
,
act
interface
{},
t
testing
.
TB
,
caller
int
)
{
if
!
reflect
.
DeepEqual
(
exp
,
act
)
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
caller
+
1
)
fmt
.
Printf
(
"%s:%d: exp: %v (%T), got: %v (%T)
\n
"
,
filepath
.
Base
(
file
),
line
,
exp
,
exp
,
act
,
act
)
t
.
FailNow
()
}
}
// isNil reports a failure if the given value is not nil. Note that values
// which cannot be nil will always fail this check.
func
isNil
(
obtained
interface
{},
t
testing
.
TB
)
{
isNilUp
(
obtained
,
t
,
1
)
}
// isNilUp is like isNil, but used inside helper functions, to ensure that the
// file and line number reported by failures corresponds to one or more levels
// up the stack.
func
isNilUp
(
obtained
interface
{},
t
testing
.
TB
,
caller
int
)
{
if
!
_isNil
(
obtained
)
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
caller
+
1
)
fmt
.
Printf
(
"%s:%d: expected nil, got: %v
\n
"
,
filepath
.
Base
(
file
),
line
,
obtained
)
t
.
FailNow
()
}
}
// notNil reports a failure if the given value is nil.
func
notNil
(
obtained
interface
{},
t
testing
.
TB
)
{
notNilUp
(
obtained
,
t
,
1
)
}
// notNilUp is like notNil, but used inside helper functions, to ensure that the
// file and line number reported by failures corresponds to one or more levels
// up the stack.
func
notNilUp
(
obtained
interface
{},
t
testing
.
TB
,
caller
int
)
{
if
_isNil
(
obtained
)
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
caller
+
1
)
fmt
.
Printf
(
"%s:%d: expected non-nil, got: %v
\n
"
,
filepath
.
Base
(
file
),
line
,
obtained
)
t
.
FailNow
()
}
}
// _isNil is a helper function for isNil and notNil, and should not be used
// directly.
func
_isNil
(
obtained
interface
{})
bool
{
if
obtained
==
nil
{
return
true
}
switch
v
:=
reflect
.
ValueOf
(
obtained
);
v
.
Kind
()
{
case
reflect
.
Chan
,
reflect
.
Func
,
reflect
.
Interface
,
reflect
.
Map
,
reflect
.
Ptr
,
reflect
.
Slice
:
return
v
.
IsNil
()
}
return
false
}
core/corehttp/logs.go
浏览文件 @
90896f28
...
...
@@ -24,7 +24,10 @@ func newWriteErrNotifier(w io.Writer) (io.Writer, <-chan error) {
func
(
w
*
writeErrNotifier
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
n
,
err
:=
w
.
w
.
Write
(
b
)
if
err
!=
nil
{
w
.
errs
<-
err
select
{
case
w
.
errs
<-
err
:
default
:
}
}
return
n
,
err
}
...
...
thirdparty/eventlog/option.go
浏览文件 @
90896f28
package
eventlog
import
(
"bufio"
"io"
"os"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2"
)
// init sets up sane defaults
...
...
@@ -18,6 +16,7 @@ func init() {
Configure
(
LevelError
)
}
// Global writer group for logs to output to
var
WriterGroup
=
new
(
MirrorWriter
)
type
Option
func
()
...
...
@@ -39,13 +38,6 @@ var TextFormatter = func() {
logrus
.
SetFormatter
(
&
logrus
.
TextFormatter
{})
}
type
LogRotatorConfig
struct
{
Filename
string
MaxSizeMB
int
MaxBackups
int
MaxAgeDays
int
}
func
Output
(
w
io
.
Writer
)
Option
{
return
func
()
{
logrus
.
SetOutput
(
w
)
...
...
@@ -53,18 +45,6 @@ func Output(w io.Writer) Option {
}
}
func
OutputRotatingLogFile
(
config
LogRotatorConfig
)
Option
{
return
func
()
{
logrus
.
SetOutput
(
bufio
.
NewWriter
(
&
lumberjack
.
Logger
{
Filename
:
config
.
Filename
,
MaxSize
:
int
(
config
.
MaxSizeMB
),
MaxBackups
:
int
(
config
.
MaxBackups
),
MaxAge
:
int
(
config
.
MaxAgeDays
),
}))
}
}
// LevelDebug Option sets the log level to debug
var
LevelDebug
=
func
()
{
logrus
.
SetLevel
(
logrus
.
DebugLevel
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论