-
Notifications
You must be signed in to change notification settings - Fork 27
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
Sotirios Mantziaris
authored
Aug 12, 2020
1 parent
8a39391
commit 35cab1c
Showing
14 changed files
with
211 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
name: Running CI | ||
on: [pull_request] | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
build: | ||
name: CI | ||
|
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,3 +1,4 @@ | ||
// Package config handles config struct parsing. | ||
package config | ||
|
||
import ( | ||
|
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,2 @@ | ||
// Package harvester is a configuration library which helps setting up and monitoring configuration values in order to dynamically reconfigure your application. | ||
package harvester |
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,106 @@ | ||
package log | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"os" | ||
|
||
hclog "github.com/hashicorp/go-hclog" | ||
) | ||
|
||
var consulLog = &consul{} | ||
|
||
// ConsulLogger return a consul compatible logger. | ||
func ConsulLogger() hclog.Logger { | ||
return consulLog | ||
} | ||
|
||
type consul struct { | ||
} | ||
|
||
func (l consul) Log(level hclog.Level, msg string, args ...interface{}) { | ||
switch level { | ||
case hclog.NoLevel: | ||
case hclog.Trace: | ||
debugf(msg, args) | ||
case hclog.Debug: | ||
debugf(msg, args) | ||
case hclog.Info: | ||
infof(msg, args) | ||
case hclog.Warn: | ||
warnf(msg, args) | ||
case hclog.Error: | ||
errorf(msg, args) | ||
} | ||
} | ||
|
||
func (l consul) Trace(msg string, args ...interface{}) { | ||
debugf(msg, args) | ||
} | ||
|
||
func (l consul) Debug(msg string, args ...interface{}) { | ||
debugf(msg, args) | ||
} | ||
|
||
func (l consul) Info(msg string, args ...interface{}) { | ||
infof(msg, args) | ||
} | ||
|
||
func (l consul) Warn(msg string, args ...interface{}) { | ||
warnf(msg, args) | ||
} | ||
|
||
func (l consul) Error(msg string, args ...interface{}) { | ||
errorf(msg, args) | ||
} | ||
|
||
func (l consul) IsTrace() bool { | ||
return true | ||
} | ||
|
||
func (l consul) IsDebug() bool { | ||
return true | ||
} | ||
|
||
func (l consul) IsInfo() bool { | ||
return true | ||
} | ||
|
||
func (l consul) IsWarn() bool { | ||
return true | ||
} | ||
|
||
func (l consul) IsError() bool { | ||
return true | ||
} | ||
|
||
func (l consul) ImpliedArgs() []interface{} { | ||
return []interface{}{} | ||
} | ||
|
||
func (l consul) With(_ ...interface{}) hclog.Logger { | ||
return consulLog | ||
} | ||
|
||
func (l consul) Name() string { | ||
return "consul" | ||
} | ||
|
||
func (l consul) Named(_ string) hclog.Logger { | ||
return consulLog | ||
} | ||
|
||
func (l consul) ResetNamed(_ string) hclog.Logger { | ||
return consulLog | ||
} | ||
|
||
func (l consul) SetLevel(_ hclog.Level) { | ||
} | ||
|
||
func (l consul) StandardLogger(_ *hclog.StandardLoggerOptions) *log.Logger { | ||
return log.New(os.Stderr, "", log.LstdFlags) | ||
} | ||
|
||
func (l consul) StandardWriter(_ *hclog.StandardLoggerOptions) io.Writer { | ||
return os.Stderr | ||
} |
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,67 @@ | ||
package log | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConsul(t *testing.T) { | ||
var buf bytes.Buffer | ||
log.SetOutput(&buf) | ||
|
||
logger := ConsulLogger() | ||
|
||
t.Run("Level", func(t *testing.T) { | ||
logger.Log(hclog.Warn, "TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "WARN: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
t.Run("Trace", func(t *testing.T) { | ||
logger.Trace("TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "DEBUG: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
t.Run("Debug", func(t *testing.T) { | ||
logger.Debug("TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "DEBUG: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
t.Run("Info", func(t *testing.T) { | ||
logger.Info("TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "INFO: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
t.Run("Warn", func(t *testing.T) { | ||
logger.Warn("TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "WARN: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
t.Run("Error", func(t *testing.T) { | ||
logger.Error("TEST: %d", 123) | ||
assert.Contains(t, buf.String(), "ERROR: TEST: [123]") | ||
buf.Reset() | ||
}) | ||
|
||
assert.True(t, logger.IsTrace()) | ||
assert.True(t, logger.IsDebug()) | ||
assert.True(t, logger.IsInfo()) | ||
assert.True(t, logger.IsWarn()) | ||
assert.True(t, logger.IsError()) | ||
assert.Empty(t, logger.ImpliedArgs()) | ||
assert.Equal(t, logger, logger.With()) | ||
assert.Equal(t, "consul", logger.Name()) | ||
assert.Equal(t, logger, logger.Named("test")) | ||
assert.Equal(t, logger, logger.ResetNamed("test")) | ||
assert.IsType(t, &log.Logger{}, logger.StandardLogger(nil)) | ||
assert.Equal(t, os.Stderr, logger.StandardWriter(nil)) | ||
} |
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
Oops, something went wrong.