Documentation ¶
Overview ¶
Example (NamedUsage) ¶
package main import ( "path/filepath" "syscall" "github.com/ydb-platform/fq-connector-go/library/go/core/log" "github.com/ydb-platform/fq-connector-go/library/go/core/log/zap" "github.com/ydb-platform/fq-connector-go/library/go/core/log/zap/logrotate" ) func main() { // Note: each scheme can be registered only once and can not be unregistered // If you want to provide custom unused scheme name(remember to check for errors): _ = logrotate.RegisterNamedLogrotateSink("rotate-usr1", syscall.SIGUSR1) // Now we create logger using that cheme cfg := zap.JSONConfig(log.DebugLevel) logPath, _ := filepath.Abs("./example.log") cfg.OutputPaths = []string{"rotate-usr1://" + logPath} logger, _ := zap.New(cfg) // Now file will be reopened by SIGUSR1 logger.Debug("this log should be reopened by SIGHUP") }
Output:
Example (SimpleUsage) ¶
package main import ( "path/filepath" "syscall" "github.com/ydb-platform/fq-connector-go/library/go/core/log" "github.com/ydb-platform/fq-connector-go/library/go/core/log/zap" "github.com/ydb-platform/fq-connector-go/library/go/core/log/zap/logrotate" ) func main() { // Basic usage, when you don't need any custom preferences is quite easy. // register our logrotate sink and force it to reopen files on sighup(remember to check for errors) _ = logrotate.RegisterLogrotateSink(syscall.SIGHUP) // create zap logger as usual, using `logrotate://` instead of omitting it or using `file://` cfg := zap.JSONConfig(log.DebugLevel) logPath, _ := filepath.Abs("./example.log") cfg.OutputPaths = []string{"logrotate://" + logPath} logger, _ := zap.New(cfg) // That's all, when your process receives SIGHUP file will be reopened logger.Debug("this log should be reopened by SIGHUP") }
Output:
Example (StandaloneUsage) ¶
package main import ( "net/url" "syscall" "github.com/ydb-platform/fq-connector-go/library/go/core/log/zap/logrotate" uberzap "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func main() { // If you don't want to register scheme, or use custom logging core you can do this(remember to check for errors): u, _ := url.ParseRequestURI("/tmp/example.log") sink, _ := logrotate.NewLogrotateSink(u, syscall.SIGHUP) encoder := zapcore.NewConsoleEncoder(zapcore.EncoderConfig{MessageKey: "msg"}) core := zapcore.NewCore(encoder, sink, uberzap.NewAtomicLevel()) logger := uberzap.New(core) // Now file will be reopened by SIGHUP logger.Debug("this log should be reopened by SIGHUP") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotSupported = errors.New("logrotate sink is not supported on your platform")
Functions ¶
func NewLogrotateSink ¶
Factory for logrotate sink, which accepts os.Signals to listen to for reloading Generally if you don't build your own core it is used by zap machinery. See RegisterLogrotateSink.
func RegisterLogrotateSink ¶
Register logrotate sink in zap sink registry. This sink internally is like file sink, but listens to provided logrotate signal and reopens file when that signal is delivered This can be called only once. Any future calls will result in an error
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.