-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check running nats server for errors
- Loading branch information
Showing
4 changed files
with
166 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package logging | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/owncloud/ocis/ocis-pkg/log" | ||
) | ||
|
||
func NewLogWrapper(logger log.Logger) *LogWrapper { | ||
return &LogWrapper{logger} | ||
} | ||
|
||
// we need to wrap our logger so we can pass it to the nats server | ||
type LogWrapper struct { | ||
logger log.Logger | ||
} | ||
|
||
// Noticef logs a notice statement | ||
func (l *LogWrapper) Noticef(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Info().Msg(msg) | ||
} | ||
|
||
// Warnf logs a warning statement | ||
func (l *LogWrapper) Warnf(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Warn().Msg(msg) | ||
} | ||
|
||
// Fatalf logs a fatal statement | ||
func (l *LogWrapper) Fatalf(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Fatal().Msg(msg) | ||
} | ||
|
||
// Errorf logs an error statement | ||
func (l *LogWrapper) Errorf(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Error().Msg(msg) | ||
} | ||
|
||
// Debugf logs a debug statement | ||
func (l *LogWrapper) Debugf(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Debug().Msg(msg) | ||
} | ||
|
||
// Tracef logs a trace statement | ||
func (l *LogWrapper) Tracef(format string, v ...interface{}) { | ||
msg := fmt.Sprintf(format, v...) | ||
l.logger.Trace().Msg(msg) | ||
} |
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 nats | ||
|
||
import ( | ||
stanServer "github.com/nats-io/nats-streaming-server/server" | ||
) | ||
|
||
// RunNatsServer runs the nats streaming server | ||
func RunNatsServer(opts ...Option) (*stanServer.StanServer, error) { | ||
natsOpts := stanServer.DefaultNatsServerOptions | ||
stanOpts := stanServer.GetDefaultOptions() | ||
|
||
for _, o := range opts { | ||
o(&natsOpts, stanOpts) | ||
} | ||
s, err := stanServer.RunServerWithOpts(stanOpts, &natsOpts) | ||
return s, err | ||
} |
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,37 @@ | ||
package nats | ||
|
||
import ( | ||
natsServer "github.com/nats-io/nats-server/v2/server" | ||
stanServer "github.com/nats-io/nats-streaming-server/server" | ||
) | ||
|
||
// Option configures the nats server | ||
type Option func(*natsServer.Options, *stanServer.Options) | ||
|
||
// Host sets the host URL for the nats server | ||
func Host(url string) Option { | ||
return func(no *natsServer.Options, _ *stanServer.Options) { | ||
no.Host = url | ||
} | ||
} | ||
|
||
// Port sets the host URL for the nats server | ||
func Port(port int) Option { | ||
return func(no *natsServer.Options, _ *stanServer.Options) { | ||
no.Port = port | ||
} | ||
} | ||
|
||
// NatsOpts allows setting Options from nats package directly | ||
func NatsOpts(opt func(*natsServer.Options)) Option { | ||
return func(no *natsServer.Options, _ *stanServer.Options) { | ||
opt(no) | ||
} | ||
} | ||
|
||
// StanOpts allows setting Options from stan package directly | ||
func StanOpts(opt func(*stanServer.Options)) Option { | ||
return func(_ *natsServer.Options, so *stanServer.Options) { | ||
opt(so) | ||
} | ||
} |