|
|
@ -172,6 +172,15 @@ func init() { |
|
|
|
flag.Uint64Var(&fileSplitSize, "log.split", uint64(1204*1024*1800), "log fail split on bytes") |
|
|
|
flag.Uint64Var(&fileSplitSize, "log.split", uint64(1204*1024*1800), "log fail split on bytes") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//SetDebug set logger debug output
|
|
|
|
|
|
|
|
func SetDebug(debug bool) { |
|
|
|
|
|
|
|
if debug { |
|
|
|
|
|
|
|
alsoStdout = true |
|
|
|
|
|
|
|
withCaller = BasePathFunc |
|
|
|
|
|
|
|
logLevel = LevelDebug |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Init() (writer io.Writer, err error) { |
|
|
|
func Init() (writer io.Writer, err error) { |
|
|
|
if inited { |
|
|
|
if inited { |
|
|
|
return nil, fmt.Errorf("logkit has been inited") |
|
|
|
return nil, fmt.Errorf("logkit has been inited") |
|
|
@ -215,9 +224,9 @@ func format(level Level, msg string) string { |
|
|
|
pc, file, line, _ = runtime.Caller(3) |
|
|
|
pc, file, line, _ = runtime.Caller(3) |
|
|
|
switch withCaller { |
|
|
|
switch withCaller { |
|
|
|
case FullPATHFunc: |
|
|
|
case FullPATHFunc: |
|
|
|
context = fmt.Sprintf("%s:%03d::%30s", file, line, path.Base(runtime.FuncForPC(pc).Name())) |
|
|
|
context = fmt.Sprintf("%s:%03d::%-30s", file, line, path.Base(runtime.FuncForPC(pc).Name())) |
|
|
|
case BasePathFunc: |
|
|
|
case BasePathFunc: |
|
|
|
context = fmt.Sprintf("%s:%03d::%30s", path.Base(file), line, path.Base(runtime.FuncForPC(pc).Name())) |
|
|
|
context = fmt.Sprintf("%s:%03d::%-15s", path.Base(file), line, path.Base(runtime.FuncForPC(pc).Name())) |
|
|
|
case BasePath: |
|
|
|
case BasePath: |
|
|
|
context = fmt.Sprintf("%s:%03d", path.Base(file), line) |
|
|
|
context = fmt.Sprintf("%s:%03d", path.Base(file), line) |
|
|
|
default: |
|
|
|
default: |
|
|
@ -231,6 +240,12 @@ func format(level Level, msg string) string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func write(level Level, msg string) (err error) { |
|
|
|
func write(level Level, msg string) (err error) { |
|
|
|
|
|
|
|
if !flag.Parsed() { |
|
|
|
|
|
|
|
return fmt.Errorf("logkit write must been flag parsed") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if auto && !inited { |
|
|
|
|
|
|
|
Init() |
|
|
|
|
|
|
|
} |
|
|
|
if !inited { |
|
|
|
if !inited { |
|
|
|
return fmt.Errorf("logkit has been inited") |
|
|
|
return fmt.Errorf("logkit has been inited") |
|
|
|
} |
|
|
|
} |
|
|
|