forked from HuaweiTech/gorouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split router package into smaller packages (wip)
casualties: - no longer logging message bus stuff (but we don't want that forever) - no longer using gocheck output in travis, as gocheck doesn't deal with sub-packages very well (only runs top-level and behaves weirdly) new packages: - registry - route - config - log
- Loading branch information
Alex Suraci and Mark Rushakoff
committed
Aug 16, 2013
1 parent
897a15f
commit daa3e7c
Showing
30 changed files
with
452 additions
and
357 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 |
---|---|---|
|
@@ -12,4 +12,4 @@ install: | |
- go get -v ./... | ||
- go build -v ./... | ||
|
||
script: go test -gocheck.v -v ./... | ||
script: go test -v ./... |
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,4 +1,4 @@ | ||
package router | ||
package config | ||
|
||
import ( | ||
vcap "github.com/cloudfoundry/gorouter/common" | ||
|
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,4 +1,4 @@ | ||
package router | ||
package config | ||
|
||
import ( | ||
. "launchpad.net/gocheck" | ||
|
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 config | ||
|
||
import ( | ||
. "launchpad.net/gocheck" | ||
"testing" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } |
File renamed without changes.
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,8 @@ | ||
package log | ||
|
||
import ( | ||
. "launchpad.net/gocheck" | ||
"testing" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } |
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,70 @@ | ||
package log | ||
|
||
import ( | ||
"github.com/cloudfoundry/gorouter/common" | ||
"github.com/cloudfoundry/gorouter/config" | ||
steno "github.com/cloudfoundry/gosteno" | ||
"os" | ||
) | ||
|
||
var logger *steno.Logger | ||
|
||
var Counter = common.NewLogCounter() | ||
|
||
func init() { | ||
stenoConfig := &steno.Config{ | ||
Sinks: []steno.Sink{steno.NewIOSink(os.Stderr)}, | ||
Codec: steno.NewJsonCodec(), | ||
Level: steno.LOG_ALL, | ||
} | ||
|
||
steno.Init(stenoConfig) | ||
logger = steno.NewLogger("router.init") | ||
} | ||
|
||
func SetupLoggerFromConfig(c *config.Config) { | ||
l, err := steno.GetLogLevel(c.Logging.Level) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
s := make([]steno.Sink, 0) | ||
if c.Logging.File != "" { | ||
s = append(s, steno.NewFileSink(c.Logging.File)) | ||
} else { | ||
s = append(s, steno.NewIOSink(os.Stdout)) | ||
} | ||
|
||
if c.Logging.Syslog != "" { | ||
s = append(s, steno.NewSyslogSink(c.Logging.Syslog)) | ||
} | ||
|
||
s = append(s, Counter) | ||
|
||
stenoConfig := &steno.Config{ | ||
Sinks: s, | ||
Codec: steno.NewJsonCodec(), | ||
Level: l, | ||
} | ||
|
||
steno.Init(stenoConfig) | ||
logger = steno.NewLogger("router.global") | ||
} | ||
|
||
func Fatal(msg string) { logger.Fatal(msg) } | ||
func Error(msg string) { logger.Error(msg) } | ||
func Warn(msg string) { logger.Warn(msg) } | ||
func Info(msg string) { logger.Info(msg) } | ||
func Debug(msg string) { logger.Debug(msg) } | ||
|
||
func Fatald(data map[string]interface{}, msg string) { logger.Fatald(data, msg) } | ||
func Errord(data map[string]interface{}, msg string) { logger.Errord(data, msg) } | ||
func Warnd(data map[string]interface{}, msg string) { logger.Warnd(data, msg) } | ||
func Infod(data map[string]interface{}, msg string) { logger.Infod(data, msg) } | ||
func Debugd(data map[string]interface{}, msg string) { logger.Debugd(data, msg) } | ||
|
||
func Fatalf(msg string, vals ...interface{}) { logger.Fatalf(msg, vals...) } | ||
func Errorf(msg string, vals ...interface{}) { logger.Errorf(msg, vals...) } | ||
func Warnf(msg string, vals ...interface{}) { logger.Warnf(msg, vals...) } | ||
func Infof(msg string, vals ...interface{}) { logger.Infof(msg, vals...) } | ||
func Debugf(msg string, vals ...interface{}) { logger.Debugf(msg, vals...) } |
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,22 +1,24 @@ | ||
package router | ||
package log | ||
|
||
import ( | ||
steno "github.com/cloudfoundry/gosteno" | ||
. "launchpad.net/gocheck" | ||
|
||
"github.com/cloudfoundry/gorouter/config" | ||
) | ||
|
||
type LoggerSuite struct{} | ||
|
||
var _ = Suite(&LoggerSuite{}) | ||
|
||
func (s *LoggerSuite) TestSetupLoggerFromConfig(c *C) { | ||
cfg := DefaultConfig() | ||
cfg := config.DefaultConfig() | ||
cfg.Logging.File = "/tmp/gorouter.log" | ||
|
||
SetupLoggerFromConfig(cfg) | ||
|
||
count := logCounter.GetCount("info") | ||
count := Counter.GetCount("info") | ||
logger := steno.NewLogger("test") | ||
logger.Info("Hello") | ||
c.Assert(logCounter.GetCount("info"), Equals, count+1) | ||
c.Assert(Counter.GetCount("info"), Equals, count+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
Oops, something went wrong.