-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom filename for init log (#100)
- Loading branch information
Showing
10 changed files
with
123 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Development: false | ||
DisableCaller: false | ||
DisableStacktrace: false | ||
Encoding: json # json or console | ||
Level: info # 日志级别,INFO, WARN, ERROR | ||
Name: eagle | ||
Writers: file # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择 | ||
LoggerDir: /tmp/logs | ||
LogRollingPolicy: daily | ||
LogRotateDate: 1 | ||
LogRotateSize: 1 | ||
LogBackupCount: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/go-eagle/eagle/pkg/config" | ||
"github.com/go-eagle/eagle/pkg/log" | ||
) | ||
|
||
func main() { | ||
// load config | ||
_ = config.New(".") | ||
|
||
// print log using default filename | ||
log.Init() | ||
log.Info("test log") | ||
|
||
// print log using custom filename | ||
log.Init(log.WithFilename("custom")) | ||
log.Info("test log with filename") | ||
|
||
// print log using custom dir and filename | ||
log.Init(log.WithFilename("user/custom")) | ||
log.Info("test log with dir and filename") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package log | ||
|
||
type Option func(*Config) | ||
|
||
// WithFilename set log filename | ||
func WithFilename(filename string) Option { | ||
return func(cfg *Config) { | ||
cfg.Name = filename | ||
} | ||
} | ||
|
||
// WithLogDir set log dir | ||
func WithLogDir(dir string) Option { | ||
return func(cfg *Config) { | ||
cfg.LoggerDir = dir | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package log | ||
|
||
import "github.com/go-eagle/eagle/pkg/utils" | ||
|
||
// GetLogFile get log file absolute path | ||
func GetLogFile(filename string, suffix string) string { | ||
return utils.ConcatString(logDir, "/", hostname, "/", filename, suffix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters