-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
127 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
module cluster-restartgracefully | ||
|
||
go 1.13 | ||
go 1.14 | ||
|
||
replace github.com/AsynkronIT/protoactor-go => ../.. | ||
replace ( | ||
github.com/AsynkronIT/protoactor-go => ../.. | ||
go.etcd.io/bbolt => github.com/coreos/bbolt v1.3.5 | ||
google.golang.org/grpc => google.golang.org/grpc v1.26.0 | ||
) | ||
|
||
require ( | ||
github.com/AsynkronIT/goconsole v0.0.0-20160504192649-bfa12eebf716 | ||
github.com/AsynkronIT/protoactor-go v0.0.0-00010101000000-000000000000 | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/coreos/etcd v3.3.25+incompatible // indirect | ||
github.com/coreos/go-semver v0.3.0 // indirect | ||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect | ||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/go-redis/redis v6.15.9+incompatible | ||
github.com/gogo/protobuf v1.3.1 | ||
go.uber.org/zap v1.16.0 // indirect | ||
google.golang.org/grpc v1.25.1 | ||
) |
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
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
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 |
---|---|---|
@@ -1,24 +1,77 @@ | ||
package log | ||
|
||
type optionFn func() | ||
import ( | ||
"os" | ||
) | ||
|
||
var ( | ||
Development = &Options{ | ||
logLevel: DebugLevel, | ||
enableCaller: true, | ||
} | ||
|
||
Production = &Options{ | ||
logLevel: InfoLevel, | ||
enableCaller: false, | ||
} | ||
|
||
Current = Production | ||
) | ||
|
||
func init() { | ||
env := os.Getenv("PROTO_ACTOR_ENV") | ||
switch env { | ||
case "dev": | ||
Current = Development | ||
case "prod": | ||
Current = Production | ||
default: | ||
Current = Production | ||
} | ||
} | ||
|
||
// Options for log. | ||
type Options struct { | ||
logLevel Level | ||
enableCaller bool | ||
} | ||
|
||
// Setup is used to configure the log system | ||
func (o *Options) With(opts ...option) *Options { | ||
cloned := *o | ||
for _, opt := range opts { | ||
opt(&cloned) | ||
} | ||
return &cloned | ||
} | ||
|
||
type option func(*Options) | ||
|
||
// WithEventSubscriber option replaces the default Event subscriber with fn. | ||
// | ||
// Specifying nil will disable logging of events. | ||
func WithEventSubscriber(fn func(evt Event)) optionFn { | ||
return func() { | ||
if sub != nil { | ||
Unsubscribe(sub) | ||
} | ||
if fn != nil { | ||
sub = Subscribe(fn) | ||
} | ||
func WithEventSubscriber(fn func(evt Event)) option { | ||
return func(opts *Options) { | ||
resetEventSubscriber(fn) | ||
} | ||
} | ||
|
||
// SetOptions is used to configure the log system | ||
func SetOptions(opts ...optionFn) { | ||
for _, opt := range opts { | ||
opt() | ||
// WithCaller option will print the file name and line number. | ||
func WithCaller(enabled bool) option { | ||
return func(opts *Options) { | ||
opts.enableCaller = enabled | ||
} | ||
} | ||
|
||
func WithDefaultLevel(level Level) option { | ||
if level == DefaultLevel { | ||
level = InfoLevel | ||
} | ||
return func(opts *Options) { | ||
opts.logLevel = level | ||
} | ||
} | ||
|
||
func SetOptions(opts ...option) { | ||
Current = Current.With(opts...) | ||
} |
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