diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 35a4cd7d..60c3b651 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -43,16 +43,11 @@ }, { "ImportPath": "github.com/cloudfoundry-incubator/runtime-schema/bbs", - "Rev": "1f960419a571ef0e973d7885767f266d5c7601d8" + "Rev": "0584b2b1185bd915309fba87cb43a392e0f1ea05" }, { "ImportPath": "github.com/cloudfoundry-incubator/runtime-schema/models", - "Rev": "1f960419a571ef0e973d7885767f266d5c7601d8" - }, - { - "ImportPath": "github.com/cloudfoundry/gosteno", - "Comment": "scotty_09012012-41-g5c1406e", - "Rev": "5c1406e9ea0ab919f92e1b194169565def41147b" + "Rev": "0584b2b1185bd915309fba87cb43a392e0f1ea05" }, { "ImportPath": "github.com/cloudfoundry/gunk/natsrunner", diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs.go index 879f2973..c17519f6 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs.go @@ -10,9 +10,9 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs" "github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) //Bulletin Board System/Store @@ -137,54 +137,54 @@ type RouteEmitterBBS interface { GetRunningActualLRPsByProcessGuid(processGuid string) ([]models.ActualLRP, error) } -func NewRepBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) RepBBS { +func NewRepBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) RepBBS { return NewBBS(store, timeProvider, logger) } -func NewConvergerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) ConvergerBBS { +func NewConvergerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) ConvergerBBS { return NewBBS(store, timeProvider, logger) } -func NewAppManagerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) AppManagerBBS { +func NewAppManagerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) AppManagerBBS { return NewBBS(store, timeProvider, logger) } -func NewNsyncBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) NsyncBBS { +func NewNsyncBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) NsyncBBS { return NewBBS(store, timeProvider, logger) } -func NewAuctioneerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) AuctioneerBBS { +func NewAuctioneerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) AuctioneerBBS { return NewBBS(store, timeProvider, logger) } -func NewStagerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) StagerBBS { +func NewStagerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) StagerBBS { return NewBBS(store, timeProvider, logger) } -func NewMetricsBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) MetricsBBS { +func NewMetricsBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) MetricsBBS { return NewBBS(store, timeProvider, logger) } -func NewFileServerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) FileServerBBS { +func NewFileServerBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) FileServerBBS { return NewBBS(store, timeProvider, logger) } -func NewRouteEmitterBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) RouteEmitterBBS { +func NewRouteEmitterBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) RouteEmitterBBS { return NewBBS(store, timeProvider, logger) } -func NewTPSBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) TPSBBS { +func NewTPSBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) TPSBBS { return NewBBS(store, timeProvider, logger) } -func NewBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) *BBS { +func NewBBS(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) *BBS { return &BBS{ LockBBS: lock_bbs.New(store), - LRPBBS: lrp_bbs.New(store, timeProvider, logger), - StartAuctionBBS: start_auction_bbs.New(store, timeProvider, logger), - StopAuctionBBS: stop_auction_bbs.New(store, timeProvider, logger), - ServicesBBS: services_bbs.New(store, logger), - TaskBBS: task_bbs.New(store, timeProvider, logger), + LRPBBS: lrp_bbs.New(store, timeProvider, logger.Session("lrp-bbs")), + StartAuctionBBS: start_auction_bbs.New(store, timeProvider, logger.Session("lrp-start-auction-bbs")), + StopAuctionBBS: stop_auction_bbs.New(store, timeProvider, logger.Session("lrp-stop-auction-bbs")), + ServicesBBS: services_bbs.New(store, logger.Session("services-bbs")), + TaskBBS: task_bbs.New(store, timeProvider, logger.Session("task-bbs")), } } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs_suite_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs_suite_test.go index b49a3ac8..f24e121e 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs_suite_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/bbs_suite_test.go @@ -1,13 +1,14 @@ package bbs_test import ( - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner" . "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/config" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager" + "github.com/pivotal-golang/lager/lagertest" "testing" "time" @@ -16,7 +17,7 @@ import ( var etcdRunner *etcdstorerunner.ETCDClusterRunner var etcdClient storeadapter.StoreAdapter var timeProvider *faketimeprovider.FakeTimeProvider -var logger *gosteno.Logger +var logger lager.Logger func TestBBS(t *testing.T) { RegisterFailHandler(Fail) @@ -26,7 +27,7 @@ func TestBBS(t *testing.T) { var _ = BeforeSuite(func() { etcdRunner = etcdstorerunner.NewETCDClusterRunner(5001+config.GinkgoConfig.ParallelNode, 1) etcdClient = etcdRunner.Adapter() - logger = gosteno.NewLogger("test") + logger = lagertest.NewTestLogger("test") }) var _ = AfterSuite(func() { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs.go index 0ad40bd9..0dbdb7ec 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs.go @@ -3,18 +3,18 @@ package lrp_bbs import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type LRPBBS struct { store storeadapter.StoreAdapter timeProvider timeprovider.TimeProvider - logger *gosteno.Logger + logger lager.Logger } -func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *gosteno.Logger) *LRPBBS { +func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) *LRPBBS { return &LRPBBS{ store: store, timeProvider: timeProvider, diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs_suite_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs_suite_test.go index d7d9baf3..3bde6727 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs_suite_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_bbs_suite_test.go @@ -2,13 +2,13 @@ package lrp_bbs_test import ( . "github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs" - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner" . "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/config" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" "testing" "time" @@ -38,7 +38,7 @@ var _ = BeforeEach(func() { etcdRunner.Start() timeProvider = faketimeprovider.New(time.Unix(0, 1138)) - bbs = New(etcdClient, timeProvider, gosteno.NewLogger("test")) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) }) func itRetriesUntilStoreComesBack(action func() error) { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_convergence.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_convergence.go index 3c60758a..6e129186 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_convergence.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/lrp_bbs/lrp_convergence.go @@ -7,6 +7,7 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type compareAndSwappableDesiredLRP struct { @@ -17,17 +18,13 @@ type compareAndSwappableDesiredLRP struct { func (bbs *LRPBBS) ConvergeLRPs() { actualsByProcessGuid, err := bbs.pruneActualsWithMissingExecutors() if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.failed-to-fetch-and-prune-actual-lrps") + bbs.logger.Error("failed-to-fetch-and-prune-actual-lrps", err) return } node, err := bbs.store.ListRecursively(shared.DesiredLRPSchemaRoot) if err != nil && err != storeadapter.ErrorKeyNotFound { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.failed-to-fetch-desired-lrps") + bbs.logger.Error("failed-to-fetch-desired-lrps", err) return } @@ -39,9 +36,10 @@ func (bbs *LRPBBS) ConvergeLRPs() { desiredLRP, err := models.NewDesiredLRPFromJSON(node.Value) if err != nil { - bbs.logger.Infod(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.pruning-unparseable-desired-lrp-json") + bbs.logger.Info("pruning-invalid-desired-lrp-json", lager.Data{ + "error": err.Error(), + "payload": node.Value, + }) keysToDelete = append(keysToDelete, node.Key) continue } @@ -63,9 +61,7 @@ func (bbs *LRPBBS) ConvergeLRPs() { bbs.batchCompareAndSwapDesiredLRPs(desiredLRPsToCAS) err = bbs.RequestStopLRPInstances(stopLRPInstances) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.failed-to-request-stops") + bbs.logger.Error("failed-to-request-stops", err) } } @@ -75,11 +71,11 @@ func (bbs *LRPBBS) instancesToStop(knownDesiredProcessGuids map[string]bool, act for processGuid, actuals := range actualsByProcessGuid { if !knownDesiredProcessGuids[processGuid] { for _, actual := range actuals { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-undesired-process", lager.Data{ "process-guid": processGuid, "instance-guid": actual.InstanceGuid, "index": actual.Index, - }, "lrp-converger.detected-undesired-process") + }) stopLRPInstances = append(stopLRPInstances, models.StopLRPInstance{ ProcessGuid: processGuid, @@ -104,25 +100,27 @@ func (bbs *LRPBBS) needsReconciliation(desiredLRP models.DesiredLRP, actualLRPsF result := delta_force.Reconcile(desiredLRP.Instances, actuals) if len(result.IndicesToStart) > 0 { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-missing-instance", lager.Data{ "process-guid": desiredLRP.ProcessGuid, "desired-instances": desiredLRP.Instances, "missing-indices": result.IndicesToStart, - }, "lrp-converger.detected-missing-instance") + }) } + if len(result.GuidsToStop) > 0 { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-extra-instance", lager.Data{ "process-guid": desiredLRP.ProcessGuid, "desired-instances": desiredLRP.Instances, "extra-guids": result.GuidsToStop, - }, "lrp-converger.detected-extra-instance") + }) } + if len(result.IndicesToStopAllButOne) > 0 { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-duplicate-instance", lager.Data{ "process-guid": desiredLRP.ProcessGuid, "desired-instances": desiredLRP.Instances, "duplicated-indices": result.IndicesToStopAllButOne, - }, "lrp-converger.detected-duplicate-instance") + }) } return !result.Empty() @@ -133,17 +131,13 @@ func (bbs *LRPBBS) pruneActualsWithMissingExecutors() (map[string][]models.Actua if err == storeadapter.ErrorKeyNotFound { executorState = storeadapter.StoreNode{} } else if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.get-executors.failed") + bbs.logger.Error("failed-to-get-executors", err) return nil, err } actuals, err := bbs.GetAllActualLRPs() if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp-converger.get-actuals.failed") + bbs.logger.Error("failed-to-get-actual-lrps", err) return nil, err } @@ -156,10 +150,10 @@ func (bbs *LRPBBS) pruneActualsWithMissingExecutors() (map[string][]models.Actua if executorIsAlive { actualsByProcessGuid[actual.ProcessGuid] = append(actualsByProcessGuid[actual.ProcessGuid], actual) } else { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-actual-with-missing-executor", lager.Data{ "actual": actual, "executor-id": actual.ExecutorID, - }, "lrp-converger.identified-actual-with-missing-executor") + }) keysToDelete = append(keysToDelete, shared.ActualLRPSchemaPath(actual)) } @@ -182,10 +176,9 @@ func (bbs *LRPBBS) batchCompareAndSwapDesiredLRPs(desiredLRPsToCAS []compareAndS go func(desiredLRPToCAS compareAndSwappableDesiredLRP, newStoreNode storeadapter.StoreNode) { err := bbs.store.CompareAndSwapByIndex(desiredLRPToCAS.OldIndex, newStoreNode) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "lrp_bbs.converge.failed-to-compare-and-swap") + bbs.logger.Error("failed-to-compare-and-swap", err) } + waitGroup.Done() }(desiredLRPToCAS, newStoreNode) } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service.go index a92b26c3..d93059bd 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service.go @@ -19,6 +19,7 @@ func (bbs *ServicesBBS) GetAllExecutors() ([]models.ExecutorPresence, error) { if err == storeadapter.ErrorKeyNotFound { return []models.ExecutorPresence{}, nil } + if err != nil { return nil, err } @@ -27,12 +28,12 @@ func (bbs *ServicesBBS) GetAllExecutors() ([]models.ExecutorPresence, error) { for _, node := range node.ChildNodes { executorPresence, err := models.NewExecutorPresenceFromJSON(node.Value) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "bbs.get-all-executors.invalid-json") + bbs.logger.Error("failed-to-unmarshal-executors-json", err) continue } + executorPresences = append(executorPresences, executorPresence) } + return executorPresences, nil } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service_test.go index 9681aa1a..04f595e3 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/executor_service_test.go @@ -6,11 +6,11 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs" "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/test_helpers" ) @@ -28,16 +28,7 @@ var _ = Describe("Fetching all Executors", func() { ) BeforeEach(func() { - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - - bbs = New(etcdClient, logger) + bbs = New(etcdClient, lagertest.NewTestLogger("test")) firstExecutorPresence = models.ExecutorPresence{ ExecutorID: "first-rep", diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/file_server_service_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/file_server_service_test.go index cec5c5b0..75b68484 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/file_server_service_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/file_server_service_test.go @@ -2,14 +2,15 @@ package services_bbs_test import ( "time" + "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager/lagertest" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models/factories" - steno "github.com/cloudfoundry/gosteno" . "github.com/cloudfoundry/storeadapter/storenodematchers" "github.com/cloudfoundry/storeadapter/test_helpers" ) @@ -26,15 +27,7 @@ var _ = Describe("Fetching available file servers", func() { ) BeforeEach(func() { - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - bbs = New(etcdClient, logger) + bbs = New(etcdClient, lagertest.NewTestLogger("test")) }) Describe("MaintainFileServerPresence", func() { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/service_registrations_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/service_registrations_test.go index e3a6bcb0..c40f9a59 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/service_registrations_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/service_registrations_test.go @@ -5,25 +5,16 @@ import ( "github.com/cloudfoundry/storeadapter" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs" - steno "github.com/cloudfoundry/gosteno" ) var _ = Context("Getting Generic Services", func() { var bbs *ServicesBBS BeforeEach(func() { - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - - bbs = New(etcdClient, logger) + bbs = New(etcdClient, lagertest.NewTestLogger("test")) }) Describe("GetServiceRegistrations", func() { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/services_bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/services_bbs.go index 745808eb..14494187 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/services_bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/services_bbs/services_bbs.go @@ -1,16 +1,16 @@ package services_bbs import ( - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type ServicesBBS struct { store storeadapter.StoreAdapter - logger *steno.Logger + logger lager.Logger } -func New(store storeadapter.StoreAdapter, logger *steno.Logger) *ServicesBBS { +func New(store storeadapter.StoreAdapter, logger lager.Logger) *ServicesBBS { return &ServicesBBS{ store: store, logger: logger, diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/lrp_start_auction_convergence.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/lrp_start_auction_convergence.go index a2bb2bb1..860c3d4b 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/lrp_start_auction_convergence.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/lrp_start_auction_convergence.go @@ -7,6 +7,7 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type compareAndSwappableLRPStartAuction struct { @@ -17,9 +18,7 @@ type compareAndSwappableLRPStartAuction struct { func (bbs *StartAuctionBBS) ConvergeLRPStartAuctions(kickPendingDuration time.Duration, expireClaimedDuration time.Duration) { node, err := bbs.store.ListRecursively(shared.LRPStartAuctionSchemaRoot) if err != nil && err != storeadapter.ErrorKeyNotFound { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "start-auction-converge.failed-to-get-start-auctions") + bbs.logger.Error("failed-to-get-start-auctions", err) return } @@ -30,9 +29,10 @@ func (bbs *StartAuctionBBS) ConvergeLRPStartAuctions(kickPendingDuration time.Du for _, node := range node.ChildNodes { auction, err := models.NewLRPStartAuctionFromJSON(node.Value) if err != nil { - bbs.logger.Infod(map[string]interface{}{ - "error": err.Error(), - }, "start-auction-converge.pruning-unparseable-start-auction-json") + bbs.logger.Info("detected-invalid-start-auction-json", lager.Data{ + "error": err.Error(), + "payload": node.Value, + }) keysToDelete = append(keysToDelete, node.Key) continue @@ -42,22 +42,23 @@ func (bbs *StartAuctionBBS) ConvergeLRPStartAuctions(kickPendingDuration time.Du switch auction.State { case models.LRPStartAuctionStatePending: if bbs.timeProvider.Time().Sub(updatedAt) > kickPendingDuration { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-pending-auction", lager.Data{ "auction": auction, "kick-duration": kickPendingDuration, - }, "start-auction-converge.kick-pending-auction") + }) auctionsToCAS = append(auctionsToCAS, compareAndSwappableLRPStartAuction{ OldIndex: node.Index, NewLRPStartAuction: auction, }) } + case models.LRPStartAuctionStateClaimed: if bbs.timeProvider.Time().Sub(updatedAt) > expireClaimedDuration { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-expired-claim", lager.Data{ "auction": auction, "expiration-duration": expireClaimedDuration, - }, "start-auction-converge.removing-expired-claimed-auction") + }) keysToDelete = append(keysToDelete, node.Key) } @@ -82,10 +83,9 @@ func (bbs *StartAuctionBBS) batchCompareAndSwapLRPStartAuctions(auctionsToCAS [] go func(auctionToCAS compareAndSwappableLRPStartAuction, newStoreNode storeadapter.StoreNode) { err := bbs.store.CompareAndSwapByIndex(auctionToCAS.OldIndex, newStoreNode) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "start-auction-converge.failed-to-compare-and-swap") + bbs.logger.Error("failed-to-compare-and-swap", err) } + waitGroup.Done() }(auctionToCAS, newStoreNode) } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs.go index f8bf1496..0b5fd6c2 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs.go @@ -1,18 +1,18 @@ package start_auction_bbs import ( - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type StartAuctionBBS struct { store storeadapter.StoreAdapter timeProvider timeprovider.TimeProvider - logger *gosteno.Logger + logger lager.Logger } -func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *gosteno.Logger) *StartAuctionBBS { +func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) *StartAuctionBBS { return &StartAuctionBBS{ store: store, timeProvider: timeProvider, diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs_suite_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs_suite_test.go index f1c679d5..95f81b4a 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs_suite_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs/start_auction_bbs_suite_test.go @@ -1,11 +1,11 @@ package start_auction_bbs_test import ( - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner" "github.com/onsi/ginkgo/config" + "github.com/pivotal-golang/lager/lagertest" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/start_auction_bbs" . "github.com/onsi/ginkgo" @@ -39,7 +39,7 @@ var _ = BeforeEach(func() { etcdRunner.Start() timeProvider = faketimeprovider.New(time.Unix(0, 1138)) - bbs = New(etcdClient, timeProvider, gosteno.NewLogger("test")) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) }) func itRetriesUntilStoreComesBack(action func() error) { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/lrp_stop_auction_convergence.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/lrp_stop_auction_convergence.go index 0da8fac6..67101ae8 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/lrp_stop_auction_convergence.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/lrp_stop_auction_convergence.go @@ -7,6 +7,7 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type compareAndSwappableLRPStopAuction struct { @@ -17,9 +18,7 @@ type compareAndSwappableLRPStopAuction struct { func (bbs *StopAuctionBBS) ConvergeLRPStopAuctions(kickPendingDuration time.Duration, expireClaimedDuration time.Duration) { node, err := bbs.store.ListRecursively(shared.LRPStopAuctionSchemaRoot) if err != nil && err != storeadapter.ErrorKeyNotFound { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "stop-auction-converge.failed-to-get-stop-auctions") + bbs.logger.Error("failed-to-get-stop-auctions", err) return } @@ -30,9 +29,10 @@ func (bbs *StopAuctionBBS) ConvergeLRPStopAuctions(kickPendingDuration time.Dura for _, node := range node.ChildNodes { auction, err := models.NewLRPStopAuctionFromJSON(node.Value) if err != nil { - bbs.logger.Infod(map[string]interface{}{ - "error": err.Error(), - }, "stop-auction-converge.pruning-unparseable-stop-auction-json") + bbs.logger.Info("detected-invalid-stop-auction-json", lager.Data{ + "error": err.Error(), + "payload": node.Value, + }) keysToDelete = append(keysToDelete, node.Key) continue @@ -42,10 +42,10 @@ func (bbs *StopAuctionBBS) ConvergeLRPStopAuctions(kickPendingDuration time.Dura switch auction.State { case models.LRPStopAuctionStatePending: if bbs.timeProvider.Time().Sub(updatedAt) > kickPendingDuration { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-pending-auction", lager.Data{ "auction": auction, "kick-duration": kickPendingDuration, - }, "stop-auction-converge.kick-pending-auction") + }) auctionsToCAS = append(auctionsToCAS, compareAndSwappableLRPStopAuction{ OldIndex: node.Index, @@ -54,10 +54,10 @@ func (bbs *StopAuctionBBS) ConvergeLRPStopAuctions(kickPendingDuration time.Dura } case models.LRPStopAuctionStateClaimed: if bbs.timeProvider.Time().Sub(updatedAt) > expireClaimedDuration { - bbs.logger.Infod(map[string]interface{}{ + bbs.logger.Info("detected-expired-claimed-auction", lager.Data{ "auction": auction, "expiration-duration": expireClaimedDuration, - }, "stop-auction-converge.removing-expired-claimed-auction") + }) keysToDelete = append(keysToDelete, node.Key) } @@ -82,10 +82,9 @@ func (bbs *StopAuctionBBS) batchCompareAndSwapLRPStopAuctions(auctionsToCAS []co go func(auctionToCAS compareAndSwappableLRPStopAuction, newStoreNode storeadapter.StoreNode) { err := bbs.store.CompareAndSwapByIndex(auctionToCAS.OldIndex, newStoreNode) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "stop-auction-converge.failed-to-compare-and-swap") + bbs.logger.Error("failed-to-compare-and-swap", err) } + waitGroup.Done() }(auctionToCAS, newStoreNode) } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs.go index c39fca1e..8511cc6d 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs.go @@ -1,18 +1,18 @@ package stop_auction_bbs import ( - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type StopAuctionBBS struct { store storeadapter.StoreAdapter timeProvider timeprovider.TimeProvider - logger *gosteno.Logger + logger lager.Logger } -func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *gosteno.Logger) *StopAuctionBBS { +func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) *StopAuctionBBS { return &StopAuctionBBS{ store: store, timeProvider: timeProvider, diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs_suite_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs_suite_test.go index c2fca030..f6d3a418 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs_suite_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs/stop_auction_bbs_suite_test.go @@ -1,11 +1,11 @@ package stop_auction_bbs_test import ( - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner" "github.com/onsi/ginkgo/config" + "github.com/pivotal-golang/lager/lagertest" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/stop_auction_bbs" . "github.com/onsi/ginkgo" @@ -39,7 +39,7 @@ var _ = BeforeEach(func() { etcdRunner.Start() timeProvider = faketimeprovider.New(time.Unix(0, 1138)) - bbs = New(etcdClient, timeProvider, gosteno.NewLogger("test")) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) }) func itRetriesUntilStoreComesBack(action func() error) { diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence.go index 8cef5abf..d316cac8 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence.go @@ -7,6 +7,7 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type compareAndSwappableTask struct { @@ -35,10 +36,12 @@ func (bbs *TaskBBS) ConvergeTask(timeToClaim time.Duration, convergenceInterval return } + taskLog := bbs.logger.Session("converge-tasks") + logError := func(task models.Task, message string) { - bbs.logger.Errord(map[string]interface{}{ + taskLog.Error(message, nil, lager.Data{ "task": task, - }, message) + }) } keysToDelete := []string{} @@ -54,10 +57,11 @@ func (bbs *TaskBBS) ConvergeTask(timeToClaim time.Duration, convergenceInterval for _, node := range taskState.ChildNodes { task, err := models.NewTaskFromJSON(node.Value) if err != nil { - bbs.logger.Errord(map[string]interface{}{ + taskLog.Error("failed-to-unmarshal-task-json", err, lager.Data{ "key": node.Key, - "value": string(node.Value), - }, "task.converge.json-parse-failure") + "value": node.Value, + }) + keysToDelete = append(keysToDelete, node.Key) continue } @@ -68,7 +72,7 @@ func (bbs *TaskBBS) ConvergeTask(timeToClaim time.Duration, convergenceInterval case models.TaskStatePending: shouldMarkAsFailed := bbs.durationSinceTaskCreated(task) >= timeToClaim if shouldMarkAsFailed { - logError(task, "task.converge.failed-to-claim") + logError(task, "failed-to-claim") scheduleForCASByIndex(node.Index, markTaskFailed(task, "not claimed within time limit")) } else if shouldKickTask { scheduleForCASByIndex(node.Index, task) @@ -77,17 +81,17 @@ func (bbs *TaskBBS) ConvergeTask(timeToClaim time.Duration, convergenceInterval _, executorIsAlive := executorState.Lookup(task.ExecutorID) if !executorIsAlive { - logError(task, "task.converge.executor-disappeared") + logError(task, "executor-disappeared") scheduleForCASByIndex(node.Index, markTaskFailed(task, "executor disappeared before completion")) } else if shouldKickTask { - logError(task, "task.converge.failed-to-start") + logError(task, "failed-to-start") scheduleForCASByIndex(node.Index, demoteToPending(task)) } case models.TaskStateRunning: _, executorIsAlive := executorState.Lookup(task.ExecutorID) if !executorIsAlive { - logError(task, "task.converge.executor-disappeared") + logError(task, "executor-disappeared") scheduleForCASByIndex(node.Index, markTaskFailed(task, "executor disappeared before completion")) } case models.TaskStateCompleted: @@ -96,7 +100,7 @@ func (bbs *TaskBBS) ConvergeTask(timeToClaim time.Duration, convergenceInterval } case models.TaskStateResolving: if shouldKickTask { - logError(task, "task.converge.failed-to-resolve") + logError(task, "failed-to-resolve") scheduleForCASByIndex(node.Index, demoteToCompleted(task)) } } @@ -135,10 +139,9 @@ func (bbs *TaskBBS) batchCompareAndSwapTasks(tasksToCAS []compareAndSwappableTas go func(taskToCAS compareAndSwappableTask, newStoreNode storeadapter.StoreNode) { err := bbs.store.CompareAndSwapByIndex(taskToCAS.OldIndex, newStoreNode) if err != nil { - bbs.logger.Errord(map[string]interface{}{ - "error": err.Error(), - }, "task.converge.failed-to-compare-and-swap") + bbs.logger.Error("failed-to-compare-and-swap", err) } + waitGroup.Done() }(taskToCAS, newStoreNode) } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence_test.go index ef6ad936..ce5d9089 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/convergence_test.go @@ -8,12 +8,12 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" . "github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/test_helpers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" ) var _ = Describe("Convergence of Tasks", func() { @@ -36,21 +36,16 @@ var _ = Describe("Convergence of Tasks", func() { timeProvider = faketimeprovider.New(time.Unix(1238, 0)) - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - - bbs = New(etcdClient, timeProvider, logger) task = models.Task{ Guid: "some-guid", Stack: "pancakes", Actions: dummyActions, } + + logger := lagertest.NewTestLogger("test") + + bbs = New(etcdClient, timeProvider, logger) + servicesBBS = services_bbs.New(etcdClient, logger) }) diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_bbs.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_bbs.go index 5128cece..a8c71483 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_bbs.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_bbs.go @@ -1,18 +1,18 @@ package task_bbs import ( - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) type TaskBBS struct { store storeadapter.StoreAdapter timeProvider timeprovider.TimeProvider - logger *steno.Logger + logger lager.Logger } -func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger *steno.Logger) *TaskBBS { +func New(store storeadapter.StoreAdapter, timeProvider timeprovider.TimeProvider, logger lager.Logger) *TaskBBS { return &TaskBBS{ store: store, timeProvider: timeProvider, diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters.go index 24b1ffd3..c6373989 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters.go @@ -4,6 +4,7 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/bbs/shared" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/storeadapter" + "github.com/pivotal-golang/lager" ) func (bbs *TaskBBS) GetAllTasks() ([]models.Task, error) { @@ -20,7 +21,10 @@ func (bbs *TaskBBS) GetAllTasks() ([]models.Task, error) { for _, node := range node.ChildNodes { task, err := models.NewTaskFromJSON(node.Value) if err != nil { - bbs.logger.Errorf("cannot parse task JSON for key %s: %s", node.Key, err.Error()) + bbs.logger.Error("failed-to-unmarshal-task", err, lager.Data{ + "key": node.Key, + "value": node.Value, + }) } else { tasks = append(tasks, task) } diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters_test.go index 066ac0d1..d23ff1ac 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_getters_test.go @@ -5,10 +5,10 @@ import ( . "github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" ) var _ = Describe("Task BBS", func() { @@ -21,15 +21,7 @@ var _ = Describe("Task BBS", func() { err = nil timeProvider = faketimeprovider.New(time.Unix(1238, 0)) - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - bbs = New(etcdClient, timeProvider, logger) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) task = models.Task{ Guid: "some-guid", Stack: "pancakes", diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_lifecycle_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_lifecycle_test.go index a470cefc..6b387f79 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_lifecycle_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_lifecycle_test.go @@ -5,10 +5,10 @@ import ( . "github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" ) var _ = Describe("Task BBS", func() { @@ -21,15 +21,7 @@ var _ = Describe("Task BBS", func() { err = nil timeProvider = faketimeprovider.New(time.Unix(1238, 0)) - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - bbs = New(etcdClient, timeProvider, logger) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) task = models.Task{ Guid: "some-guid", Stack: "pancakes", diff --git a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_watchers_test.go b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_watchers_test.go index 8e64d921..923aae2a 100644 --- a/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_watchers_test.go +++ b/Godeps/_workspace/src/github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs/task_watchers_test.go @@ -6,9 +6,9 @@ import ( . "github.com/cloudfoundry-incubator/runtime-schema/bbs/task_bbs" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/lager/lagertest" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" ) @@ -22,15 +22,7 @@ var _ = Describe("Task BBS", func() { err = nil timeProvider = faketimeprovider.New(time.Unix(1238, 0)) - logSink := steno.NewTestingSink() - - steno.Init(&steno.Config{ - Sinks: []steno.Sink{logSink}, - }) - - logger := steno.NewLogger("the-logger") - steno.EnterTestMode() - bbs = New(etcdClient, timeProvider, logger) + bbs = New(etcdClient, timeProvider, lagertest.NewTestLogger("test")) task = models.Task{ Guid: "some-guid", Stack: "waffles", diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.gitignore b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.gitignore deleted file mode 100644 index 8528bb8a..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.swp -pkg -*.iml -src diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.travis.yml b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.travis.yml deleted file mode 100644 index 406cd5e1..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go -go: - - 1.1 - - tip - -matrix: - allow_failures: - - go: tip - -install: - - go get -v launchpad.net/gocheck - - go get -v ./... - - go build -v ./... diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/LICENSE b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/LICENSE deleted file mode 100644 index 11069edd..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/README.md b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/README.md deleted file mode 100644 index e4cae667..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/README.md +++ /dev/null @@ -1,90 +0,0 @@ -# Gosteno [![Build Status](https://travis-ci.org/cloudfoundry/gosteno.png?branch=master)](https://travis-ci.org/cloudfoundry/gosteno) - -Gosteno is a golang implementation of the -[steno log tool](https://github.com/cloudfoundry/steno). The feature set of -Gosteno is very similar with that of ruby steno. - -## Overview - -Core concepts behind Gosteno includes codec, sink, level, tag. - -### codec - -A codec encodes log entries to structural data, more specifically, JSON format -data. Besides JSON codecs, Gosteno provides prettified codec which generates -more human-readable data. - -### sink - -Roughly speaking, a sink is the destination where you store your log data. It's -an abstraction of the underlying data storage systems. Currently Gosteno -supports two kinds of sinks, namely IOSink and SyslogSink. IOSink includes files -and standard output while SyslogSink streams your log data to syslog daemons -such as rsyslogd. You can register as many sinks as you want. Everytime you log -information, it will be written to all the sinks you have registered. - -### level - -Gosteno supports 9 levels(from low to high): all, debug2, debug1, debug, info, -warn, error, fatal, off. You can change the level on the fly without respawning -the process. - -### tag - -In gosteno, tags are extended information that will be encoded together with -other normal log information. You can add as many tags as you want. Tag makes -the log information extensive. - -## Get Gosteno - - go get -u github.com/cloudfoundry/gosteno - -## Getting started - -Here is a short but complete program showing how to registering sinks, chosing -codec, tagging the information. - - package main - - import ( - "github.com/cloudfoundry/gosteno" - "os" - ) - - func main() { - c := &gosteno.Config{ - Sinks: []gosteno.Sink{ - gosteno.NewFileSink("./a.log"), - gosteno.NewIOSink(os.Stdout), - gosteno.NewSyslogSink("foobar"), - }, - Level: gosteno.LOG_INFO, - Codec: gosteno.NewJsonCodec(), - EnableLOC: true, - } - gosteno.Init(c) - logger := gosteno.NewLogger("test") - t := gosteno.NewTaggedLogger(logger, map[string]string{"foo": "bar", "hello": "world"}) - t.Info("Hello") - } - -## Change logger properties on the fly - -Changing logger properties such as log level without restarting system is -allowed in Gosteno. It is achieved through a http interface by some APIs and -data is exchanged as JSON: - - 1. GET /regexp : get something like {"RexExp": "test$", "Level": "fatal"} - 2. PUT /regexp : put with data like {"RegExp": "test$", "Level":"fatal"} - 3. GET /loggers/{name} : get information about the logger by name - 4. PUT /loggers/{name} : put with data like {"Level" : "fatal" } - 5. GET /loggers : get information about all loggers - -## Supported platforms - -Currently targeting modern flavors of darwin and linux. - -## License - -Apache 2.0 - diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/codec.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/codec.go deleted file mode 100644 index 73905fcd..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/codec.go +++ /dev/null @@ -1,5 +0,0 @@ -package gosteno - -type Codec interface { - EncodeRecord(record *Record) ([]byte, error) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config.go deleted file mode 100644 index 86afc21c..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config.go +++ /dev/null @@ -1,8 +0,0 @@ -package gosteno - -type Config struct { - Sinks []Sink - Level LogLevel - Codec Codec - EnableLOC bool -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config_test.go deleted file mode 100644 index d2e44e1a..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/config_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package gosteno - -import ( - . "launchpad.net/gocheck" -) - -type ConfigSuite struct { -} - -var _ = Suite(&ConfigSuite{}) - -func (s *ConfigSuite) TestReInitLevel(c *C) { - levels := []LogLevel{LOG_INFO, LOG_DEBUG, LOG_WARN} - - for _, level := range levels { - Init(&Config{Level: level}) - - l := NewLogger("reinit") - c.Assert(l.Level(), Equals, level) - } -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/README.md b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/README.md deleted file mode 100644 index 5ee91dd7..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# gosteno-prettify - -gosteno-prettify is a command line tool which parses json formatted log lines -from file(s), or stdin, and displays a more human friendly version of each line -to stdout. - -## Setup - - go get -u github.com/cloudfoundry/gosteno - cd $GOPATH/src/github.com/cloudfoundry/gosteno/gosteno-prettify - go install - -Don't forget to add the $GOPATH/bin to the $PATH - -## Usage - - gosteno-prettify [OPTS] [FILE(s)] - -Examples : - - gosteno-prettify f - g - Prettify f's contents, then standard input, then g's contents. - - gosteno-prettify - Prettify contents of stdin. - -Fire `gosteno-prettify -h` to see more options. diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/prettifier.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/prettifier.go deleted file mode 100644 index 9403955e..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/gosteno-prettify/prettifier.go +++ /dev/null @@ -1,121 +0,0 @@ -package main - -import ( - "bufio" - "flag" - "fmt" - "github.com/cloudfoundry/gosteno" - "io" - "os" - "strings" -) - -var prettifier *gosteno.JsonPrettifier - -var ignoreParseError = false -var helptext = `Usage: gosteno-prettify [OPTS] [FILE(s)] - -Parses json formatted log lines from FILE(s), or stdin, -and displays a more human friendly version of each line to stdout. - -Examples : - - gosteno-prettify f - g - Prettify f's contents, then standard input, then g's contents. - - gosteno-prettify - Prettify contents of stdin. - -Options: - - -h - Display help - -a - Omit location and data in order to provide well-aligned logs - -s - Donot complain about errors in parsing logs -` - -func prettifyFromIO(src io.Reader) { - buf := bufio.NewReader(src) - - lineno := 0 - for { - line, err := buf.ReadString('\n') - if err != nil { - break - } - lineno++ - - i := strings.Index(line, "{") - var prefix string - if i > 0 { - prefix = line[:i] - line = line[i:] - } - r, e := prettifier.DecodeJsonLogEntry(line) - if e != nil { - if !ignoreParseError { - fmt.Fprintf(os.Stderr, "steno-prettify: Malformed json at line %d : %s", lineno, line) - } - continue - } - s, _ := prettifier.EncodeRecord(r) - fmt.Println(fmt.Sprintf("%s%s", prefix, string(s))) - } -} - -func prettifyFromFile(logFile string) error { - f, e := os.Open(logFile) - if e != nil { - return e - } - defer f.Close() - - prettifyFromIO(f) - - return nil -} - -func main() { - excludedFields := gosteno.EXCLUDE_NONE - - h := flag.Bool("h", false, "Show help") - a := flag.Bool("a", false, "Omit location and data in order to provide well-aligned logs") - s := flag.Bool("s", false, "Ignore errors in parsing logs") - - flag.Usage = func() { - fmt.Fprintf(os.Stderr, helptext) - } - - flag.Parse() - - if *h { - flag.Usage() - return - } - if *a { - excludedFields |= gosteno.EXCLUDE_FILE | gosteno.EXCLUDE_LINE | gosteno.EXCLUDE_METHOD | gosteno.EXCLUDE_DATA - } - if *s { - ignoreParseError = true - } - - prettifier = gosteno.NewJsonPrettifier(excludedFields) - - args := flag.Args() - if len(args) > 0 { - for _, f := range args { - if f == "-" { - prettifyFromIO(os.Stdin) - } else { - e := prettifyFromFile(f) - if e != nil { - fmt.Fprintln(os.Stderr, e) - } - } - } - } else { - prettifyFromIO(os.Stdin) - } -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink.go deleted file mode 100644 index 5ff5cd10..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink.go +++ /dev/null @@ -1,67 +0,0 @@ -package gosteno - -import ( - "bufio" - "os" - "sync" -) - -type IOSink struct { - writer *bufio.Writer - codec Codec - file *os.File - - sync.Mutex -} - -func NewIOSink(file *os.File) *IOSink { - writer := bufio.NewWriter(file) - - x := new(IOSink) - x.writer = writer - x.file = file - - return x -} - -func NewFileSink(path string) *IOSink { - file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - panic(err) - } - - return NewIOSink(file) -} - -func (x *IOSink) AddRecord(record *Record) { - bytes, _ := x.codec.EncodeRecord(record) - - x.Lock() - defer x.Unlock() - - x.writer.Write(bytes) - - // Need to append a newline for IO sink - x.writer.WriteString("\n") -} - -func (x *IOSink) Flush() { - x.Lock() - defer x.Unlock() - - x.writer.Flush() -} - -func (x *IOSink) SetCodec(codec Codec) { - x.Lock() - defer x.Unlock() - - x.codec = codec -} - -func (x *IOSink) GetCodec() Codec { - x.Lock() - defer x.Unlock() - - return x.codec -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink_test.go deleted file mode 100644 index e1fbe9bc..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/io_sink_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package gosteno - -import ( - "bufio" - "io" - . "launchpad.net/gocheck" -) - -type IOSinkSuite struct { -} - -var _ = Suite(&IOSinkSuite{}) - -func (s *IOSinkSuite) TestAddRecord(c *C) { - pReader, pWriter := io.Pipe() - sink := NewIOSink(nil) - sink.writer = bufio.NewWriter(pWriter) - sink.SetCodec(NewJsonCodec()) - - go func(msg string) { - record := NewRecord("source", LOG_INFO, msg, nil) - sink.AddRecord(record) - sink.Flush() - pWriter.Close() - }("Hello, \nworld") - - bufReader := bufio.NewReader(pReader) - msg, err := bufReader.ReadString('\n') - c.Assert(err, IsNil) - c.Assert(msg, Matches, `{.*"Hello, \\nworld".*}\n`) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec.go deleted file mode 100644 index 113b1918..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec.go +++ /dev/null @@ -1,21 +0,0 @@ -package gosteno - -import ( - "encoding/json" -) - -type JsonCodec struct { -} - -func NewJsonCodec() Codec { - return new(JsonCodec) -} - -func (j *JsonCodec) EncodeRecord(record *Record) ([]byte, error) { - b, err := json.Marshal(record) - if err != nil { - return json.Marshal(map[string]string{"error": err.Error()}) - } - - return b, err -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec_test.go deleted file mode 100644 index a0556c7d..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_codec_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package gosteno - -import ( - "fmt" - . "launchpad.net/gocheck" -) - -type JsonCodecSuite struct { - JsonCodec -} - -var _ = Suite(&JsonCodecSuite{}) - -func (s *JsonCodecSuite) TestJsonCodec(c *C) { - r := NewRecord("source", LOG_INFO, "Hello world", nil) - m, err := s.EncodeRecord(r) - c.Assert(err, IsNil) - - // The names of these fields are a direct copy of the fields used by the Ruby - // version of steno to prevent breaking the prettifiers. Some of these fields - // can be changed (e.g. `process_id` -> `pid`, `log_level` -> `level), but - // only as long as the prettifiers are also updated. - fields := []string{ - "timestamp", - "process_id", - "source", - "log_level", - "message", - "data", - } - - for _, f := range fields { - c.Check(string(m), Matches, fmt.Sprintf(`{.*"%s":.*}`, f)) - } -} - -func (s *JsonCodecSuite) TestTimestampIsFormattedAsFloat(c *C) { - r := NewRecord("source", LOG_INFO, "Hello world", nil) - m, err := s.EncodeRecord(r) - c.Assert(err, IsNil) - c.Assert(string(m), Matches, `.*"timestamp":\d{10}\.\d{9},.*`) -} - -func (s *JsonCodecSuite) TestEmptyFileLineMethodNotIncluded(c *C) { - r := NewRecord("source", LOG_INFO, "Hello world", nil) - m, err := s.EncodeRecord(r) - c.Assert(err, IsNil) - c.Check(string(m), Not(Matches), `.*"file":.*`) - c.Check(string(m), Not(Matches), `.*"line":.*`) - c.Check(string(m), Not(Matches), `.*"method":.*`) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier.go deleted file mode 100644 index c47ed665..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier.go +++ /dev/null @@ -1,105 +0,0 @@ -package gosteno - -import ( - "bytes" - "encoding/json" - "fmt" - "strconv" - "strings" - "text/template" - "time" -) - -const ( - EXCLUDE_NONE = 0 - - EXCLUDE_LEVEL = 1 << (iota - 1) - EXCLUDE_TIMESTAMP - EXCLUDE_FILE - EXCLUDE_LINE - EXCLUDE_METHOD - EXCLUDE_DATA - EXCLUDE_MESSAGE -) - -type JsonPrettifier struct { - entryTemplate *template.Template -} - -func NewJsonPrettifier(flag int) *JsonPrettifier { - fields := []string{ - "{{encodeLevel .Level}}", - "{{encodeTimestamp .Timestamp}}", - "{{encodeFile .File}}", - "{{encodeLine .Line}}", - "{{encodeMethod .Method}}", - "{{encodeData .Data}}", - "{{encodeMessage .Message}}", - } - - for i, _ := range fields { - // the shift count must be an unsigned integer - if (flag & (1 << uint(i))) != 0 { - fields[i] = "" - } - } - - prettifier := new(JsonPrettifier) - format := strings.Join(fields, "") - funcMap := template.FuncMap{ - "encodeTimestamp": encodeTimestamp, - "encodeFile": encodeFile, - "encodeMethod": encodeMethod, - "encodeLine": encodeLine, - "encodeData": encodeData, - "encodeLevel": encodeLevel, - "encodeMessage": encodeMessage, - } - prettifier.entryTemplate = template.Must(template.New("EntryTemplate").Funcs(funcMap).Parse(format)) - - return prettifier -} - -func (p *JsonPrettifier) DecodeJsonLogEntry(logEntry string) (*Record, error) { - record := new(Record) - err := json.Unmarshal([]byte(logEntry), record) - return record, err -} - -func (p *JsonPrettifier) EncodeRecord(record *Record) ([]byte, error) { - buffer := bytes.NewBufferString("") - err := p.entryTemplate.Execute(buffer, record) - return buffer.Bytes(), err -} - -func encodeLevel(level LogLevel) string { - return fmt.Sprintf("%s ", strings.ToUpper(level.String())) -} - -func encodeTimestamp(t RecordTimestamp) string { - ut := time.Unix(int64(t), 0) - return fmt.Sprintf("%s ", ut.Format("2006-01-02 15:04:05")) -} - -func encodeFile(file string) string { - index := strings.LastIndex(file, "/") - return fmt.Sprintf("%s:", file[index+1:]) -} - -func encodeLine(line int) string { - return fmt.Sprintf("%s:", strconv.Itoa(line)) -} - -func encodeMethod(method string) string { - index := strings.LastIndex(method, ".") - return fmt.Sprintf("%s ", method[index+1:]) -} - -func encodeData(data map[string]interface{}) (string, error) { - b, err := json.Marshal(data) - return fmt.Sprintf("%s ", string(b)), err -} - -func encodeMessage(message string) string { - return message -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier_test.go deleted file mode 100644 index d5056c1c..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/json_prettifier_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package gosteno - -import ( - "fmt" - . "launchpad.net/gocheck" -) - -type JsonPrettifierSuite struct { -} - -var _ = Suite(&JsonPrettifierSuite{}) - -func (s *JsonPrettifierSuite) TestConst(c *C) { - c.Assert(EXCLUDE_NONE, Equals, 0) - c.Assert(EXCLUDE_LEVEL, Equals, 1<<0) - c.Assert(EXCLUDE_TIMESTAMP, Equals, 1<<1) - c.Assert(EXCLUDE_LINE, Equals, 1<<3) -} - -func (s *JsonPrettifierSuite) TestConstOrder(c *C) { - record := NewRecord("source", LOG_INFO, "Hello, world", map[string]interface{}{"foo": "bar"}) - - prettifier1 := NewJsonPrettifier(EXCLUDE_FILE | EXCLUDE_DATA) - bytes1, _ := prettifier1.EncodeRecord(record) - - prettifier2 := NewJsonPrettifier(EXCLUDE_DATA | EXCLUDE_FILE) - bytes2, _ := prettifier2.EncodeRecord(record) - - c.Assert(string(bytes1), Equals, string(bytes2)) -} - -func (s *JsonPrettifierSuite) TestEncodeRecord(c *C) { - config.EnableLOC = true - record := NewRecord("source", LOG_INFO, "Hello, world", map[string]interface{}{"foo": "bar"}) - config.EnableLOC = false - l := record.Line - - prettifier := NewJsonPrettifier(EXCLUDE_NONE) - b, err := prettifier.EncodeRecord(record) - c.Assert(err, IsNil) - - // One example: - // INFO 2012-09-27 16:53:40 json_prettifier_test.go:34:TestEncodeRecord {"foo":"bar"} Hello, world - c.Assert(string(b), Matches, fmt.Sprintf(`INFO .*son_prettifier_test.go:%d:TestEncodeRecord.*{"foo":"bar"}.*Hello, world`, l)) -} - -func (s *JsonPrettifierSuite) TestExclude(c *C) { - config.EnableLOC = true - record := NewRecord("source", LOG_INFO, "Hello, world", map[string]interface{}{"foo": "bar"}) - config.EnableLOC = false - - prettifier := NewJsonPrettifier(EXCLUDE_DATA | EXCLUDE_LINE) - bytes, _ := prettifier.EncodeRecord(record) - - // One example: - // INFO Wed, 19 Sep 2012 10:51:57 CST json_prettifier_test.go:TestExclude Hello, world - c.Assert(string(bytes), Matches, `INFO .*son_prettifier_test.go:TestExclude Hello, world`) -} - -func (s *JsonPrettifierSuite) TestDecodeLogEntry(c *C) { - config.EnableLOC = true - record := NewRecord("source", LOG_INFO, "Hello, world", map[string]interface{}{"foo": "bar"}) - config.EnableLOC = false - l := record.Line - t := record.Timestamp - b, _ := NewJsonCodec().EncodeRecord(record) - entry := string(b) - - prettifier := NewJsonPrettifier(EXCLUDE_NONE) - record, err := prettifier.DecodeJsonLogEntry(entry) - - c.Assert(err, IsNil) - c.Assert(record.Timestamp, Equals, t) - c.Assert(record.Line, Equals, l) - c.Assert(record.Level, Equals, LOG_INFO) - c.Assert(record.Method, Matches, ".*TestDecodeLogEntry$") - c.Assert(record.Message, Equals, "Hello, world") - c.Assert(record.File, Matches, ".*json_prettifier_test.go") - c.Assert(record.Data["foo"], Equals, "bar") - - // test err with invalid log level - entry = `{"Message":"hi","Log_Level":"enoent"}` - record, err = prettifier.DecodeJsonLogEntry(entry) - - c.Assert(err, NotNil) - c.Assert(err.Error(), Matches, ".*enoent.*") -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level.go deleted file mode 100644 index a3d54b89..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level.go +++ /dev/null @@ -1,70 +0,0 @@ -package gosteno - -import ( - "encoding/json" - "fmt" -) - -type LogLevel struct { - Name string - Priority int -} - -var ( - LOG_OFF = defineLogLevel("off", 0) - LOG_FATAL = defineLogLevel("fatal", 1) - LOG_ERROR = defineLogLevel("error", 5) - LOG_WARN = defineLogLevel("warn", 10) - LOG_INFO = defineLogLevel("info", 15) - LOG_DEBUG = defineLogLevel("debug", 16) - LOG_DEBUG1 = defineLogLevel("debug1", 17) - LOG_DEBUG2 = defineLogLevel("debug2", 18) - LOG_ALL = defineLogLevel("all", 30) -) - -var levels = make(map[string]LogLevel) - -func defineLogLevel(n string, p int) LogLevel { - x := LogLevel{Name: n, Priority: p} - - levels[n] = x - - return x -} - -func GetLogLevel(name string) (LogLevel, error) { - var x LogLevel - - if x, ok := levels[name]; ok { - return x, nil - } - - err := fmt.Errorf("Undefined log level: %s", name) - return x, err -} - -func (x LogLevel) MarshalJSON() ([]byte, error) { - return json.Marshal(x.Name) -} - -func (x *LogLevel) UnmarshalJSON(data []byte) error { - var n string - - err := json.Unmarshal(data, &n) - if err != nil { - return err - } - - y, err := GetLogLevel(n) - if err != nil { - return err - } - - *x = y - - return nil -} - -func (l LogLevel) String() string { - return l.Name -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level_test.go deleted file mode 100644 index 650a9348..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/log_level_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package gosteno - -import ( - "encoding/json" - . "launchpad.net/gocheck" -) - -type LogLevelSuite struct { -} - -var _ = Suite(&LogLevelSuite{}) - -func (s *LogLevelSuite) TestNewLogLevel(c *C) { - level := defineLogLevel("foobar", 100) - c.Assert(level, NotNil) - c.Assert(level.Name, Equals, "foobar") - c.Assert(level.Priority, Equals, 100) -} - -func (s *LogLevelSuite) TestGetLevel(c *C) { - l, err := GetLogLevel("info") - c.Assert(l, Equals, LOG_INFO) - c.Assert(err, IsNil) -} - -func (s *LogLevelSuite) TestGetNotExistLevel(c *C) { - l, err := GetLogLevel("foobar") - c.Assert(l, Equals, LogLevel{}) - c.Assert(err, NotNil) -} - -func (s *LogLevelSuite) TestMarshal(c *C) { - m, err := json.Marshal(LOG_INFO) - - c.Assert(err, IsNil) - c.Assert(string(m), Equals, "\"info\"") -} - -func (s *LogLevelSuite) TestUnmarshal(c *C) { - var l LogLevel - - err := json.Unmarshal([]byte("\"info\""), &l) - - c.Assert(err, IsNil) - c.Assert(l, Equals, LOG_INFO) -} - -func (s *LogLevelSuite) TestUnmarshalError(c *C) { - var l LogLevel - - err := json.Unmarshal([]byte("\"undefined\""), &l) - - c.Assert(err.Error(), Matches, "Undefined log level: .*") - c.Assert(l, Equals, LogLevel{}) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger.go deleted file mode 100644 index d58b68ef..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger.go +++ /dev/null @@ -1,217 +0,0 @@ -package gosteno - -import ( - "fmt" - "sync" -) - -type L interface { - Level() LogLevel - Log(x LogLevel, m string, d map[string]interface{}) -} - -type Logger struct { - sync.Mutex - L - d map[string]interface{} -} - -type BaseLogger struct { - name string - sinks []Sink - level LogLevel -} - -func (l *BaseLogger) Level() LogLevel { - return l.level -} - -func (l *BaseLogger) Log(x LogLevel, m string, d map[string]interface{}) { - if l.Level().Priority < x.Priority { - return - } - - r := NewRecord(l.name, x, m, d) - for _, s := range l.sinks { - s.AddRecord(r) - s.Flush() - } - - if x == LOG_FATAL { - panic(m) - } -} - -func (l *Logger) Log(x LogLevel, m string, d map[string]interface{}) { - var r map[string]interface{} - - if d != nil && l.d != nil { - r = make(map[string]interface{}) - - // Copy the loggers data - for k, v := range l.d { - r[k] = v - } - - // Overwrite specified data - for k, v := range d { - r[k] = v - } - } else if d != nil { - r = d - } else { - r = l.d - } - - l.L.Log(x, m, r) -} - -func (l *Logger) Set(k string, v interface{}) { - l.Lock() - - if l.d == nil { - l.d = make(map[string]interface{}) - } - - l.d[k] = v - - l.Unlock() -} - -func (l *Logger) Get(k string) (rv interface{}) { - l.Lock() - - if l.d != nil { - rv = l.d[k] - } - - l.Unlock() - - return -} - -func (l *Logger) Copy() (rv *Logger) { - rv = &Logger{L: l.L} - - l.Lock() - - for k, v := range l.d { - rv.Set(k, v) - } - - l.Unlock() - - return -} - -func (l *Logger) Fatal(m string) { - l.Log(LOG_FATAL, m, nil) -} - -func (l *Logger) Error(m string) { - l.Log(LOG_ERROR, m, nil) -} - -func (l *Logger) Warn(m string) { - l.Log(LOG_WARN, m, nil) -} - -func (l *Logger) Info(m string) { - l.Log(LOG_INFO, m, nil) -} - -func (l *Logger) Debug(m string) { - l.Log(LOG_DEBUG, m, nil) -} - -func (l *Logger) Debug1(m string) { - l.Log(LOG_DEBUG1, m, nil) -} - -func (l *Logger) Debug2(m string) { - l.Log(LOG_DEBUG2, m, nil) -} - -func (l *Logger) Fatald(d map[string]interface{}, m string) { - l.Log(LOG_FATAL, m, d) -} - -func (l *Logger) Errord(d map[string]interface{}, m string) { - l.Log(LOG_ERROR, m, d) -} - -func (l *Logger) Warnd(d map[string]interface{}, m string) { - l.Log(LOG_WARN, m, d) -} - -func (l *Logger) Infod(d map[string]interface{}, m string) { - l.Log(LOG_INFO, m, d) -} - -func (l *Logger) Debugd(d map[string]interface{}, m string) { - l.Log(LOG_DEBUG, m, d) -} - -func (l *Logger) Debug1d(d map[string]interface{}, m string) { - l.Log(LOG_DEBUG1, m, d) -} - -func (l *Logger) Debug2d(d map[string]interface{}, m string) { - l.Log(LOG_DEBUG2, m, d) -} - -func (l *Logger) Fatalf(f string, a ...interface{}) { - l.Log(LOG_FATAL, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Errorf(f string, a ...interface{}) { - l.Log(LOG_ERROR, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Warnf(f string, a ...interface{}) { - l.Log(LOG_WARN, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Infof(f string, a ...interface{}) { - l.Log(LOG_INFO, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Debugf(f string, a ...interface{}) { - l.Log(LOG_DEBUG, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Debug1f(f string, a ...interface{}) { - l.Log(LOG_DEBUG1, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Debug2f(f string, a ...interface{}) { - l.Log(LOG_DEBUG2, fmt.Sprintf(f, a...), nil) -} - -func (l *Logger) Fataldf(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_FATAL, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Errordf(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_ERROR, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Warndf(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_WARN, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Infodf(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_INFO, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Debugdf(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_DEBUG, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Debug1df(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_DEBUG1, fmt.Sprintf(f, a...), d) -} - -func (l *Logger) Debug2df(d map[string]interface{}, f string, a ...interface{}) { - l.Log(LOG_DEBUG2, fmt.Sprintf(f, a...), d) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger_test.go deleted file mode 100644 index 42939487..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/logger_test.go +++ /dev/null @@ -1,146 +0,0 @@ -package gosteno - -import ( - . "launchpad.net/gocheck" -) - -type LoggerSuite struct { - nSink *nullSink -} - -var _ = Suite(&LoggerSuite{}) - -func NumLogger() int { - return len(loggers) -} - -func (s *LoggerSuite) SetUpTest(c *C) { - cfg := Config{} - s.nSink = newNullSink() - cfg.Sinks = []Sink{s.nSink} - loggers = make(map[string]*BaseLogger) - - Init(&cfg) -} - -func (s *LoggerSuite) TearDownTest(c *C) { - Init(&Config{}) - - loggers = nil - loggerRegexp = nil - loggerRegexpLevel = nil -} - -func (s *LoggerSuite) TestLoggersNum(c *C) { - c.Assert(len(loggers), Equals, 0) -} - -func (s *LoggerSuite) TestLogLevel(c *C) { - bl := &BaseLogger{ - name: "bar", - level: LOG_INFO, - sinks: []Sink{&nullSink{}}, - } - - higher := []LogLevel{LOG_INFO, LOG_WARN, LOG_ERROR} - for _, l := range higher { - s := &nullSink{} - bl.sinks = []Sink{s} - bl.Log(l, "hello", nil) - c.Assert(len(s.records), Equals, 1) - } - - lower := []LogLevel{LOG_DEBUG, LOG_DEBUG1, LOG_DEBUG2, LOG_ALL} - for _, l := range lower { - s := &nullSink{} - bl.sinks = []Sink{s} - bl.Log(l, "hello", nil) - c.Assert(len(s.records), Equals, 0) - } -} - -func (s *LoggerSuite) TestLog(c *C) { - logger := NewLogger("foobar") - logger.Info("Hello, world") - c.Assert(s.nSink.records, HasLen, 1) - bytes, _ := config.Codec.EncodeRecord(s.nSink.records[0]) - c.Assert(string(bytes), Matches, "{.*Hello, world.*}") -} - -func (s *LoggerSuite) TestLevelVisibility(c *C) { - logger := NewLogger("whatever") - logger.Info("hello") - logger.Debug("world") - // The default level is 'info', so 'debug' will be hidden - c.Assert(s.nSink.records, HasLen, 1) -} - -func (s *LoggerSuite) TestCreatingDupLogger(c *C) { - logger1 := NewLogger("foobar") - logger2 := NewLogger("foobar") - c.Assert(logger1, DeepEquals, logger2) -} - -func (s *LoggerSuite) TestPanic(c *C) { - logger := NewLogger("foobar") - c.Assert(func() { logger.Fatal("fail!") }, PanicMatches, "fail!") - c.Assert(func() { logger.Fatalf("fail!%s", "fail!") }, PanicMatches, "fail!fail!") -} - -var logWithDataExamples = []struct { - A, B, R map[string]interface{} -}{ - { - A: map[string]interface{}{"foo": "bar"}, - B: nil, - R: map[string]interface{}{"foo": "bar"}, - }, - { - A: nil, - B: map[string]interface{}{"foo": "bar"}, - R: map[string]interface{}{"foo": "bar"}, - }, - { - A: map[string]interface{}{"foo": "qux"}, - B: map[string]interface{}{"foo": "bar"}, - R: map[string]interface{}{"foo": "bar"}, - }, - { - A: map[string]interface{}{"foo": "qux", "baz": "zap"}, - B: map[string]interface{}{"foo": "bar"}, - R: map[string]interface{}{"foo": "bar", "baz": "zap"}, - }, -} - -func (s *LoggerSuite) TestLogWithData(c *C) { - for _, e := range logWithDataExamples { - n := newNullSink() - l := NewLogger("logger") - l.L.(*BaseLogger).sinks = []Sink{n} - - l.d = e.A - l.Log(LOG_INFO, "message", e.B) - - c.Check(n.records[0].Data, DeepEquals, e.R) - } -} - -func (s *LoggerSuite) TestLoggerSetGet(c *C) { - l := NewLogger("logger") - l.Set("key", "value") - c.Check(l.Get("key"), Equals, "value") -} - -func (s *LoggerSuite) TestLoggerCopy(c *C) { - x := NewLogger("logger") - x.Set("key", "value") - - y := x.Copy() - c.Check(y.Get("key"), Equals, "value") - - y.Set("key", "other_value") - c.Check(y.Get("key"), Equals, "other_value") - - // The original logger should be left unchanged - c.Check(x.Get("key"), Equals, "value") -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/null_sink_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/null_sink_test.go deleted file mode 100644 index a3e74a8f..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/null_sink_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package gosteno - -type nullSink struct { - records []*Record -} - -func newNullSink() *nullSink { - nSink := new(nullSink) - nSink.records = make([]*Record, 0, 10) - return nSink -} - -func (nSink *nullSink) AddRecord(record *Record) { - nSink.records = append(nSink.records, record) -} - -func (nSink *nullSink) Flush() { - -} - -func (nSink *nullSink) SetCodec(codec Codec) { - -} - -func (nSink *nullSink) GetCodec() Codec { - return nil -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/perf_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/perf_test.go deleted file mode 100644 index 837c42b2..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/perf_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package gosteno - -import ( - "testing" -) - -func BenchmarkNoSink(b *testing.B) { - Init(&Config{}) - - loggers = make(map[string]*BaseLogger) - logger := NewLogger("nosink") - - performBenchmark(logger, b) -} - -func BenchmarkDevNullSink(b *testing.B) { - Init(&Config{ - Sinks: []Sink{NewFileSink("/dev/null")}, - }) - - loggers = make(map[string]*BaseLogger) - logger := NewLogger("dev_null_sink") - - performBenchmark(logger, b) -} - -func BenchmarkDevNullSinkWithLOC(b *testing.B) { - Init(&Config{ - Sinks: []Sink{NewFileSink("/dev/null")}, - EnableLOC: true, - }) - - loggers = make(map[string]*BaseLogger) - logger := NewLogger("dev_null_sink_with_loc") - - performBenchmark(logger, b) -} - -func BenchmarkDevNullSinkWithData(b *testing.B) { - Init(&Config{ - Sinks: []Sink{NewFileSink("/dev/null")}, - }) - - loggers = make(map[string]*BaseLogger) - logger := NewLogger("dev_null_sink_with_data") - logger.Set("key1", "value1") - logger.Set("key2", "value2") - - performBenchmark(logger, b) -} - -func performBenchmark(logger *Logger, b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - logger.Info("Hello, world.") - } -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record.go deleted file mode 100644 index b3b30946..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record.go +++ /dev/null @@ -1,65 +0,0 @@ -package gosteno - -import ( - "fmt" - "os" - "runtime" - "strings" - "time" -) - -type RecordTimestamp float64 - -func (t RecordTimestamp) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%.9f", t)), nil -} - -type Record struct { - Timestamp RecordTimestamp `json:"timestamp"` - Pid int `json:"process_id"` - Source string `json:"source"` - Level LogLevel `json:"log_level"` - Message string `json:"message"` - Data map[string]interface{} `json:"data"` - File string `json:"file,omitempty"` - Line int `json:"line,omitempty"` - Method string `json:"method,omitempty"` -} - -var pid int - -func init() { - pid = os.Getpid() -} - -func NewRecord(s string, l LogLevel, m string, d map[string]interface{}) *Record { - r := &Record{ - Timestamp: RecordTimestamp(time.Now().UnixNano()) / 1000000000, - Pid: pid, - Source: s, - Level: l, - Message: m, - Data: d, - } - - if getConfig().EnableLOC { - var function *runtime.Func - var file string - var line int - - pc := make([]uintptr, 50) - nptrs := runtime.Callers(2, pc) - for i := 0; i < nptrs; i++ { - function = runtime.FuncForPC(pc[i]) - file, line = function.FileLine(pc[i]) - if !strings.HasSuffix(file, "logger.go") { - break - } - } - r.File = file - r.Line = line - r.Method = function.Name() - } - - return r -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record_test.go deleted file mode 100644 index 25bbe5d4..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/record_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package gosteno - -import ( - . "launchpad.net/gocheck" -) - -type RecordSuite struct{} - -var _ = Suite(&RecordSuite{}) - -func (s *RecordSuite) TestNewRecordWithLOC(c *C) { - config.EnableLOC = true - r := NewRecord("source", LOG_INFO, "hello", nil) - config.EnableLOC = false - - c.Check(r.File, Matches, ".*record_test.go$") - c.Check(r.Line, Equals, 13) - c.Check(r.Method, Matches, `.*\.\(\*RecordSuite\)\.TestNewRecordWithLOC`) -} - -func (s *RecordSuite) TestNewRecordWithoutLOC(c *C) { - r := NewRecord("source", LOG_INFO, "hello", nil) - - c.Check(r.File, Equals, "") - c.Check(r.Line, Equals, 0) - c.Check(r.Method, Equals, "") -} - -func (s *RecordSuite) TestRecordPid(c *C) { - r := NewRecord("source", LOG_INFO, "hello", nil) - - c.Check(r.Pid, Not(Equals), 0) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/regexp.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/regexp.go deleted file mode 100644 index ff284c44..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/regexp.go +++ /dev/null @@ -1,65 +0,0 @@ -package gosteno - -import ( - "regexp" -) - -// loggerRegexp* used to match log name and log level -var loggerRegexp *regexp.Regexp -var loggerRegexpLevel *LogLevel - -func SetLoggerRegexp(pattern string, level LogLevel) error { - loggersMutex.Lock() - defer loggersMutex.Unlock() - - clearLoggerRegexp() - return setLoggerRegexp(pattern, level) -} - -func ClearLoggerRegexp() { - loggersMutex.Lock() - defer loggersMutex.Unlock() - - clearLoggerRegexp() -} - -func setLoggerRegexp(pattern string, level LogLevel) error { - regExp, err := regexp.Compile(pattern) - if err != nil { - return err - } - - loggerRegexp = regExp - loggerRegexpLevel = &level - - for name, logger := range loggers { - if loggerRegexp.MatchString(name) { - logger.level = level - } - } - - return nil -} - -func clearLoggerRegexp() { - if loggerRegexp == nil { - return - } - - for name, logger := range loggers { - if loggerRegexp.MatchString(name) { - logger.level = getConfig().Level - } - } - - loggerRegexp = nil - loggerRegexpLevel = nil -} - -func computeLevel(name string) LogLevel { - if loggerRegexpLevel != nil && loggerRegexp.MatchString(name) { - return *loggerRegexpLevel - } - - return getConfig().Level -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/sink.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/sink.go deleted file mode 100644 index 32603dbf..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/sink.go +++ /dev/null @@ -1,9 +0,0 @@ -package gosteno - -type Sink interface { - AddRecord(record *Record) - Flush() - - SetCodec(codec Codec) - GetCodec() Codec -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno.go deleted file mode 100644 index 9a6b177d..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno.go +++ /dev/null @@ -1,85 +0,0 @@ -package gosteno - -import ( - "encoding/json" - "sync" -) - -// Global configs -var config Config - -// loggersMutex protects accesses to loggers and regexp -var loggersMutex = &sync.Mutex{} - -// loggersMutex protects accesses to loggers and regexp -var configMutex = &sync.RWMutex{} - -// loggers only saves BaseLogger -var loggers = make(map[string]*BaseLogger) - -func Init(c *Config) { - loggersMutex.Lock() - defer loggersMutex.Unlock() - - if c.Level == (LogLevel{}) { - c.Level = LOG_INFO - } - - if c.Codec == nil { - c.Codec = NewJsonCodec() - } - - if c.Sinks == nil { - c.Sinks = []Sink{} - } - - for _, sink := range c.Sinks { - if sink.GetCodec() == nil { - sink.SetCodec(c.Codec) - } - } - - setConfig(*c) - - for name, _ := range loggers { - loggers[name] = nil - } -} - -func NewLogger(name string) *Logger { - loggersMutex.Lock() - defer loggersMutex.Unlock() - - l := loggers[name] - if l == nil { - bl := &BaseLogger{ - name: name, - sinks: getConfig().Sinks, - level: computeLevel(name), - } - - loggers[name] = bl - l = bl - } - - return &Logger{L: l} -} - -func getConfig() Config { - configMutex.RLock() - defer configMutex.RUnlock() - - return config -} - -func setConfig(newConfig Config) { - configMutex.Lock() - defer configMutex.Unlock() - - config = newConfig -} - -func loggersInJson() string { - bytes, _ := json.Marshal(loggers) - return string(bytes) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno_test.go deleted file mode 100644 index b86510be..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/steno_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package gosteno - -import ( - . "launchpad.net/gocheck" - "os" - "testing" -) - -func Test(t *testing.T) { - TestingT(t) -} - -type StenoSuite struct { -} - -var _ = Suite(&StenoSuite{}) - -func (s *StenoSuite) SetUpTest(c *C) { - cfg := Config{} - cfg.Sinks = []Sink{NewIOSink(os.Stdout)} - - loggers = make(map[string]*BaseLogger) - - Init(&cfg) -} - -func (s *StenoSuite) TearDownTest(c *C) { - Init(&Config{}) - - loggers = nil - loggerRegexp = nil - loggerRegexpLevel = nil -} - -func (s *StenoSuite) TestInitLoggers(c *C) { - c.Assert(loggers, HasLen, 0) -} - -func (s *StenoSuite) TestDefaultConfig(c *C) { - c.Assert(config.Level, Equals, LOG_INFO) -} - -func (s *StenoSuite) TestLoggersInJson(c *C) { - c.Assert(loggersInJson(), Matches, "{.*}") -} - -func (s *StenoSuite) TestSetLoggerRegexp(c *C) { - // level is a field of BaseLogger, hence type cast is needed - logger1 := NewLogger("test").L.(*BaseLogger) - logger2 := NewLogger("test2").L.(*BaseLogger) - logger3 := NewLogger("test3").L.(*BaseLogger) - - c.Assert(logger1.level, Equals, LOG_INFO) - c.Assert(logger2.level, Equals, LOG_INFO) - c.Assert(logger3.level, Equals, LOG_INFO) - - SetLoggerRegexp("te", LOG_FATAL) - c.Assert(logger1.level, Equals, LOG_FATAL) - c.Assert(logger2.level, Equals, LOG_FATAL) - c.Assert(logger3.level, Equals, LOG_FATAL) - - SetLoggerRegexp("test", LOG_ERROR) - c.Assert(logger1.level, Equals, LOG_ERROR) - c.Assert(logger2.level, Equals, LOG_ERROR) - c.Assert(logger3.level, Equals, LOG_ERROR) - - SetLoggerRegexp("test$", LOG_WARN) - c.Assert(logger1.level, Equals, LOG_WARN) - c.Assert(logger2.level, Equals, LOG_INFO) - c.Assert(logger3.level, Equals, LOG_INFO) -} - -func (s *StenoSuite) TestClearLoggerRegexp(c *C) { - // level is a field of BaseLogger, hence type cast is needed - logger1 := NewLogger("test").L.(*BaseLogger) - logger2 := NewLogger("test2").L.(*BaseLogger) - logger3 := NewLogger("test3").L.(*BaseLogger) - - c.Assert(logger1.level, Equals, LOG_INFO) - c.Assert(logger2.level, Equals, LOG_INFO) - c.Assert(logger3.level, Equals, LOG_INFO) - - SetLoggerRegexp("test", LOG_FATAL) - c.Assert(logger1.level, Equals, LOG_FATAL) - c.Assert(logger2.level, Equals, LOG_FATAL) - c.Assert(logger3.level, Equals, LOG_FATAL) - - ClearLoggerRegexp() - c.Assert(logger1.level, Equals, LOG_INFO) - c.Assert(logger2.level, Equals, LOG_INFO) - c.Assert(logger3.level, Equals, LOG_INFO) -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog.go deleted file mode 100644 index 7b9a06b2..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog.go +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !windows,!plan9 - -// Package syslog provides a simple interface to the system log service. It -// can send messages to the syslog daemon using UNIX domain sockets, UDP, or -// TCP connections. -package syslog - -import ( - "errors" - "fmt" - "log" - "net" - "os" - "time" -) - -type Priority int - -const ( - // From /usr/include/sys/syslog.h. - // These are the same on Linux, BSD, and OS X. - LOG_EMERG Priority = iota - LOG_ALERT - LOG_CRIT - LOG_ERR - LOG_WARNING - LOG_NOTICE - LOG_INFO - LOG_DEBUG -) - -// A Writer is a connection to a syslog server. -type Writer struct { - priority Priority - prefix string - conn serverConn -} - -type serverConn interface { - writeBytes(p Priority, prefix string, b []byte) (int, error) - writeString(p Priority, prefix string, s string) (int, error) - close() error -} - -type netConn struct { - conn net.Conn -} - -// New establishes a new connection to the system log daemon. -// Each write to the returned writer sends a log message with -// the given priority and prefix. -func New(priority Priority, prefix string) (w *Writer, err error) { - return Dial("", "", priority, prefix) -} - -// Dial establishes a connection to a log daemon by connecting -// to address raddr on the network net. -// Each write to the returned writer sends a log message with -// the given priority and prefix. -func Dial(network, raddr string, priority Priority, prefix string) (w *Writer, err error) { - if prefix == "" { - prefix = os.Args[0] - } - var conn serverConn - if network == "" { - conn, err = unixSyslog() - } else { - var c net.Conn - c, err = net.Dial(network, raddr) - conn = netConn{c} - } - return &Writer{priority, prefix, conn}, err -} - -// Write sends a log message to the syslog daemon. -func (w *Writer) Write(b []byte) (int, error) { - if w.priority > LOG_DEBUG || w.priority < LOG_EMERG { - return 0, errors.New("log/syslog: invalid priority") - } - return w.conn.writeBytes(w.priority, w.prefix, b) -} - -func (w *Writer) writeString(p Priority, s string) (int, error) { - return w.conn.writeString(p, w.prefix, s) -} - -func (w *Writer) Close() error { return w.conn.close() } - -// Emerg logs a message using the LOG_EMERG priority. -func (w *Writer) Emerg(m string) (err error) { - _, err = w.writeString(LOG_EMERG, m) - return err -} - -// Alert logs a message using the LOG_ALERT priority. -func (w *Writer) Alert(m string) (err error) { - _, err = w.writeString(LOG_ALERT, m) - return err -} - -// Crit logs a message using the LOG_CRIT priority. -func (w *Writer) Crit(m string) (err error) { - _, err = w.writeString(LOG_CRIT, m) - return err -} - -// Err logs a message using the LOG_ERR priority. -func (w *Writer) Err(m string) (err error) { - _, err = w.writeString(LOG_ERR, m) - return err -} - -// Warning logs a message using the LOG_WARNING priority. -func (w *Writer) Warning(m string) (err error) { - _, err = w.writeString(LOG_WARNING, m) - return err -} - -// Notice logs a message using the LOG_NOTICE priority. -func (w *Writer) Notice(m string) (err error) { - _, err = w.writeString(LOG_NOTICE, m) - return err -} - -// Info logs a message using the LOG_INFO priority. -func (w *Writer) Info(m string) (err error) { - _, err = w.writeString(LOG_INFO, m) - return err -} - -// Debug logs a message using the LOG_DEBUG priority. -func (w *Writer) Debug(m string) (err error) { - _, err = w.writeString(LOG_DEBUG, m) - return err -} - -func (n netConn) writeString(p Priority, prefix string, s string) (int, error) { - return n.writeBytes(p, prefix, []byte(s)) -} - -func (n netConn) writeBytes(p Priority, prefix string, b []byte) (int, error) { - nl := "" - if len(b) == 0 || b[len(b)-1] != '\n' { - nl = "\n" - } - - n.conn.SetWriteDeadline(time.Now().Add(1 * time.Second)) - - _, err := fmt.Fprintf(n.conn, "<%d>%s: %s%s", p, prefix, b, nl) - if err != nil { - return 0, err - } - - return len(b), nil -} - -func (n netConn) close() error { - return n.conn.Close() -} - -// NewLogger creates a log.Logger whose output is written to -// the system log service with the specified priority. The logFlag -// argument is the flag set passed through to log.New to create -// the Logger. -func NewLogger(p Priority, logFlag int) (*log.Logger, error) { - s, err := New(p, "") - if err != nil { - return nil, err - } - return log.New(s, "", logFlag), nil -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_test.go deleted file mode 100644 index fb313699..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_test.go +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !windows,!plan9 - -package syslog - -import ( - "io" - "io/ioutil" - "log" - "net" - "os" - "path" - "testing" - "time" -) - -var serverAddr string - -func runSyslog(c net.PacketConn, done chan<- string) { - var buf [4096]byte - var rcvd string = "" - for { - n, _, err := c.ReadFrom(buf[0:]) - if err != nil || n == 0 { - break - } - rcvd += string(buf[0:n]) - } - done <- rcvd -} - -func startServer(done chan<- string) { - c, e := net.ListenPacket("udp", "127.0.0.1:0") - if e != nil { - log.Fatalf("net.ListenPacket failed udp :0 %v", e) - } - serverAddr = c.LocalAddr().String() - c.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) - go runSyslog(c, done) -} - -func skipNetTest(t *testing.T) bool { - if testing.Short() { - // Depends on syslog daemon running, and sometimes it's not. - t.Logf("skipping syslog test during -short") - return true - } - return false -} - -func TestNew(t *testing.T) { - if skipNetTest(t) { - return - } - s, err := New(LOG_INFO, "") - if err != nil { - t.Fatalf("New() failed: %s", err) - } - // Don't send any messages. - s.Close() -} - -func TestNewLogger(t *testing.T) { - if skipNetTest(t) { - return - } - f, err := NewLogger(LOG_INFO, 0) - if f == nil { - t.Error(err) - } -} - -func TestDial(t *testing.T) { - if skipNetTest(t) { - return - } - l, err := Dial("", "", LOG_ERR, "syslog_test") - if err != nil { - t.Fatalf("Dial() failed: %s", err) - } - l.Close() -} - -func TestUDPDial(t *testing.T) { - done := make(chan string) - startServer(done) - l, err := Dial("udp", serverAddr, LOG_INFO, "syslog_test") - if err != nil { - t.Fatalf("syslog.Dial() failed: %s", err) - } - msg := "udp test" - l.Info(msg) - expected := "<6>syslog_test: udp test\n" - rcvd := <-done - if rcvd != expected { - t.Fatalf("s.Info() = '%q', but wanted '%q'", rcvd, expected) - } -} - -func TestWrite(t *testing.T) { - tests := []struct { - pri Priority - pre string - msg string - exp string - }{ - {LOG_ERR, "syslog_test", "", "<3>syslog_test: \n"}, - {LOG_ERR, "syslog_test", "write test", "<3>syslog_test: write test\n"}, - // Write should not add \n if there already is one - {LOG_ERR, "syslog_test", "write test 2\n", "<3>syslog_test: write test 2\n"}, - } - - for _, test := range tests { - done := make(chan string) - startServer(done) - l, err := Dial("udp", serverAddr, test.pri, test.pre) - if err != nil { - t.Fatalf("syslog.Dial() failed: %s", err) - } - _, err = io.WriteString(l, test.msg) - if err != nil { - t.Fatalf("WriteString() failed: %s", err) - } - rcvd := <-done - if rcvd != test.exp { - t.Fatalf("s.Info() = '%q', but wanted '%q'", rcvd, test.exp) - } - } -} - -func TestWriteTimesOut(t *testing.T) { - tmpdir, err := ioutil.TempDir(os.TempDir(), "write-timeout-test") - if err != nil { - t.Fatalf("ioutil.TempFile() failed: %s", err) - } - - socketFile := path.Join(tmpdir, "test.sock") - - _, err = net.Listen("unix", socketFile) - if err != nil { - t.Fatalf("net.Listen() failed to listen on socket: %s", err) - } - - w, err := Dial("unix", socketFile, LOG_INFO, "syslog_test") - - if err != nil { - t.Fatalf("syslog.Dial() failed: %s", err) - } - - firstFailure := make(chan error) - - go func() { - for { - _, err = io.WriteString(w, "timing out") - if err != nil { - firstFailure <- err - break - } - } - }() - - select { - case err := <-firstFailure: - switch err.(type) { - case *net.OpError: - if !err.(*net.OpError).Timeout() { - t.Fatalf("WriteString() error = '%#v', but wanted a timeout error", err) - } - default: - t.Fatalf("WriteString() error = '%#v', but wanted a timeout error", err) - } - case <-time.After(10 * time.Second): - t.Fatalf("WriteString() never returned an error") - } -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_unix.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_unix.go deleted file mode 100644 index d928cbc5..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_unix.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !windows,!plan9 - -package syslog - -import ( - "errors" - "net" -) - -// unixSyslog opens a connection to the syslog daemon running on the -// local machine using a Unix domain socket. - -func unixSyslog() (conn serverConn, err error) { - logTypes := []string{"unixgram", "unix"} - logPaths := []string{"/dev/log", "/var/run/syslog"} - var raddr string - for _, network := range logTypes { - for _, path := range logPaths { - raddr = path - conn, err := net.Dial(network, raddr) - if err != nil { - continue - } else { - return netConn{conn}, nil - } - } - } - return nil, errors.New("Could not connect to local syslog socket") -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_windows.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_windows.go deleted file mode 100644 index 8d99e2e5..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog/syslog_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package syslog provides a simple interface to the system log service. -package syslog - -// BUG(brainman): This package is not implemented on Windows yet. diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink.go deleted file mode 100644 index 0a00a37a..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink.go +++ /dev/null @@ -1,83 +0,0 @@ -// +build !windows,!plan9 - -package gosteno - -import ( - syslog "github.com/cloudfoundry/gosteno/syslog" - "sync" - "errors" -) - -const ( - MaxMessageSize = 1024 * 3 - TruncatePostfix = "..." -) - -type Syslog struct { - writer *syslog.Writer - codec Codec - - sync.Mutex -} - -func NewSyslogSink(namespace string) *Syslog { - writer, err := syslog.New(syslog.LOG_DEBUG, namespace) - if err != nil { - panic(errors.New("Could not setup logging to syslog: " + err.Error())) - } - - syslog := new(Syslog) - syslog.writer = writer - return syslog -} - -func (s *Syslog) AddRecord(record *Record) { - truncate(record) - - bytes, _ := s.codec.EncodeRecord(record) - msg := string(bytes) - - s.Lock() - defer s.Unlock() - - switch record.Level { - case LOG_FATAL: - s.writer.Crit(msg) - case LOG_ERROR: - s.writer.Err(msg) - case LOG_WARN: - s.writer.Warning(msg) - case LOG_INFO: - s.writer.Info(msg) - case LOG_DEBUG, LOG_DEBUG1, LOG_DEBUG2: - s.writer.Debug(msg) - default: - panic("Unknown log level: " + record.Level.Name) - } -} - -func (s *Syslog) Flush() { - // No impl. -} - -func (s *Syslog) SetCodec(codec Codec) { - s.Lock() - defer s.Unlock() - - s.codec = codec -} - -func (s *Syslog) GetCodec() Codec { - s.Lock() - defer s.Unlock() - - return s.codec -} - -func truncate(record *Record) { - if len(record.Message) <= MaxMessageSize { - return - } - - record.Message = record.Message[:MaxMessageSize-len(TruncatePostfix)] + TruncatePostfix -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink_test.go deleted file mode 100644 index 7dade2a1..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/syslog_sink_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// +build !windows,!plan9 - -package gosteno - -import ( - "fmt" - . "launchpad.net/gocheck" - "os" - "strings" -) - -type SyslogSinkSuite struct { -} - -var _ = Suite(&SyslogSinkSuite{}) - -func (s *SyslogSinkSuite) TestTruncate(c *C) { - msg := generateString(MaxMessageSize - 1) - record := &Record{ - Message: msg, - } - truncate(record) - c.Check(record.Message, Equals, msg) - - msg2 := generateString(MaxMessageSize + 1) - record2 := &Record{ - Message: msg2, - } - truncate(record2) - c.Check(len(record2.Message), Equals, MaxMessageSize) - c.Check(record2.Message[:MaxMessageSize-3], Equals, msg2[:MaxMessageSize-3]) - c.Check(strings.HasSuffix(record2.Message, "..."), Equals, true) -} - -func generateString(length int) (ret string) { - file, _ := os.Open("/dev/urandom") - b := make([]byte, length/2) - file.Read(b) - file.Close() - - if length%2 == 0 { - ret = fmt.Sprintf("%x", b) - } else { - ret = fmt.Sprintf("0%x", b) - } - - return -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink.go deleted file mode 100644 index ae1526b1..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink.go +++ /dev/null @@ -1,70 +0,0 @@ -package gosteno - -import ( - "sync" -) - -type TestingSink struct { - records []*Record - - sync.RWMutex -} - -var theGlobalTestSink *TestingSink -var globalSyncMutex = &sync.RWMutex{} - -func EnterTestMode(logLevel ...LogLevel) { - globalSyncMutex.Lock() - defer globalSyncMutex.Unlock() - - theGlobalTestSink = NewTestingSink() - - stenoConfig := Config{ - Sinks: []Sink{theGlobalTestSink}, - } - - if len(logLevel) > 0 { - stenoConfig.Level = logLevel[0] - } - - Init(&stenoConfig) -} - -func GetMeTheGlobalTestSink() *TestingSink { - globalSyncMutex.RLock() - defer globalSyncMutex.RUnlock() - - return theGlobalTestSink -} - -func NewTestingSink() *TestingSink { - return &TestingSink{ - records: make([]*Record, 0, 10), - } -} - -func (tSink *TestingSink) AddRecord(record *Record) { - tSink.Lock() - defer tSink.Unlock() - - tSink.records = append(tSink.records, record) -} - -func (tSink *TestingSink) Flush() { - -} - -func (tSink *TestingSink) SetCodec(codec Codec) { - -} - -func (tSink *TestingSink) GetCodec() Codec { - return nil -} - -func (tSink *TestingSink) Records() []*Record { - tSink.RLock() - defer tSink.RUnlock() - - return tSink.records -} diff --git a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink_test.go b/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink_test.go deleted file mode 100644 index c504bbb0..00000000 --- a/Godeps/_workspace/src/github.com/cloudfoundry/gosteno/testing_sink_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package gosteno - -import ( - . "launchpad.net/gocheck" -) - -type TestingSinkSuite struct { -} - -var _ = Suite(&TestingSinkSuite{}) - -func (s *TestingSinkSuite) TestAddRecord(c *C) { - sink := NewTestingSink() - - data := map[string]interface{}{"a": "b"} - record := NewRecord("source", LOG_INFO, "Hello, world!", data) - sink.AddRecord(record) - - c.Assert(sink.Records(), HasLen, 1) - c.Check(sink.Records()[0].Message, Equals, "Hello, world!") - c.Check(sink.Records()[0].Data, DeepEquals, data) -} diff --git a/integration/integration_test.go b/integration/integration_test.go index cee61687..f2d32223 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -10,7 +10,6 @@ import ( "github.com/cloudfoundry-incubator/executor/api" "github.com/cloudfoundry-incubator/rep/reprunner" "github.com/cloudfoundry-incubator/runtime-schema/models" - "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/pivotal-golang/lager/lagertest" @@ -35,7 +34,8 @@ var _ = Describe("The Rep", func() { fakeExecutor.AllowUnhandledRequests = true fakeExecutor.RouteToHandler("GET", "/ping", ghttp.RespondWith(http.StatusOK, nil)) - bbs = Bbs.NewBBS(etcdRunner.Adapter(), timeprovider.NewTimeProvider(), gosteno.NewLogger("the-logger")) + bbs = Bbs.NewBBS(etcdRunner.Adapter(), timeprovider.NewTimeProvider(), lagertest.NewTestLogger("test")) + runner = reprunner.New( representativePath, executorID, diff --git a/main.go b/main.go index 134b24da..f41a5591 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,6 @@ import ( "github.com/cloudfoundry-incubator/rep/task_scheduler" Bbs "github.com/cloudfoundry-incubator/runtime-schema/bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - steno "github.com/cloudfoundry/gosteno" "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter/etcdstoreadapter" "github.com/cloudfoundry/storeadapter/workerpool" @@ -63,12 +62,6 @@ var natsPassword = flag.String( "Password for nats user", ) -var syslogName = flag.String( - "syslogName", - "", - "syslog name", -) - var heartbeatInterval = flag.Duration( "heartbeatInterval", 60*time.Second, @@ -121,7 +114,7 @@ func main() { } logger := cf_lager.New("rep") - bbs := initializeRepBBS(initializeStenoLogger()) + bbs := initializeRepBBS(logger) executorClient := client.New(http.DefaultClient, *executorURL) lrpStopper := initializeLRPStopper(bbs, executorClient, logger) @@ -158,33 +151,20 @@ func main() { } } -func initializeStenoLogger() *steno.Logger { - stenoConfig := steno.Config{ - Sinks: []steno.Sink{steno.NewIOSink(os.Stdout)}, - } - - if *syslogName != "" { - stenoConfig.Sinks = append(stenoConfig.Sinks, steno.NewSyslogSink(*syslogName)) - } - - steno.Init(&stenoConfig) - return steno.NewLogger("rep") -} - -func initializeRepBBS(logger *steno.Logger) Bbs.RepBBS { +func initializeRepBBS(logger lager.Logger) Bbs.RepBBS { etcdAdapter := etcdstoreadapter.NewETCDStoreAdapter( strings.Split(*etcdCluster, ","), workerpool.NewWorkerPool(10), ) bbs := Bbs.NewRepBBS(etcdAdapter, timeprovider.NewTimeProvider(), logger) + err := etcdAdapter.Connect() if err != nil { - logger.Errord(map[string]interface{}{ - "error": err, - }, "rep.etcd-connect.failed") + logger.Fatal("failed-to-connect-to-etcd", err) os.Exit(1) } + return bbs }