本文整理汇总了Golang中github.com/pivotal-golang/lager.Logger.RegisterSink方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.RegisterSink方法的具体用法?Golang Logger.RegisterSink怎么用?Golang Logger.RegisterSink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pivotal-golang/lager.Logger
的用法示例。
在下文中一共展示了Logger.RegisterSink方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitLoggerFromConfig
func InitLoggerFromConfig(logger lager.Logger, c *config.Config, logCounter *schema.LogCounter) {
if c.Logging.File != "" {
file, err := os.OpenFile(c.Logging.File, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
logger.Fatal("error-opening-log-file", err, lager.Data{"file": c.Logging.File})
}
var logLevel lager.LogLevel
switch c.Logging.Level {
case DEBUG:
logLevel = lager.DEBUG
case INFO:
logLevel = lager.INFO
case ERROR:
logLevel = lager.ERROR
case FATAL:
logLevel = lager.FATAL
default:
panic(fmt.Errorf("unknown log level: %s", c.Logging.Level))
}
logger.RegisterSink(lager.NewWriterSink(file, logLevel))
}
logger.RegisterSink(logCounter)
}
示例2:
var _ = Describe("Logger", func() {
var logger lager.Logger
var testSink *lagertest.TestSink
var component = "my-component"
var action = "my-action"
var logData = lager.Data{
"foo": "bar",
"a-number": 7,
}
BeforeEach(func() {
logger = lager.NewLogger(component)
testSink = lagertest.NewTestSink()
logger.RegisterSink(testSink)
})
var TestCommonLogFeatures = func(level lager.LogLevel) {
var log lager.LogFormat
BeforeEach(func() {
log = testSink.Logs()[0]
})
It("writes a log to the sink", func() {
Ω(testSink.Logs()).Should(HaveLen(1))
})
It("records the source component", func() {
Ω(log.Source).Should(Equal(component))
示例3: TestAuction
flag.StringVar(&reportName, "reportName", "report", "report name")
}
func TestAuction(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Auction Suite")
}
var _ = BeforeSuite(func() {
runtime.GOMAXPROCS(runtime.NumCPU())
fmt.Printf("Running in %s communicationMode\n", communicationMode)
startReport()
logger = lager.NewLogger("sim")
logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))
sessionsToTerminate = []*gexec.Session{}
switch communicationMode {
case InProcess:
cells = buildInProcessReps()
case HTTP:
cells = launchExternalHTTPReps()
default:
panic(fmt.Sprintf("unknown communication mode: %s", communicationMode))
}
})
var _ = BeforeEach(func() {
var err error
workPool, err = workpool.NewWorkPool(workers)
示例4: TestGlager
func TestGlager(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Glager Test Suite")
}
var _ = Describe(".ContainSequence", func() {
var (
buffer *gbytes.Buffer
logger lager.Logger
expectedSource = "some-source"
)
BeforeEach(func() {
buffer = gbytes.NewBuffer()
logger = lager.NewLogger(expectedSource)
logger.RegisterSink(lager.NewWriterSink(buffer, lager.DEBUG))
})
Context("when actual contains an entry", func() {
var (
action = "some-action"
expectedAction = fmt.Sprintf("%s.%s", expectedSource, action)
expectedDataKey = "some-key"
expectedDataValue = "some-value"
)
Context("that is an info", func() {
BeforeEach(func() {
logger.Info(action, lager.Data{expectedDataKey: expectedDataValue})
})
示例5:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Chug", func() {
var (
logger lager.Logger
stream chan Entry
pipeReader *io.PipeReader
pipeWriter *io.PipeWriter
)
BeforeEach(func() {
pipeReader, pipeWriter = io.Pipe()
logger = lager.NewLogger("chug-test")
logger.RegisterSink(lager.NewWriterSink(pipeWriter, lager.DEBUG))
stream = make(chan Entry, 100)
go Chug(pipeReader, stream)
})
AfterEach(func() {
pipeWriter.Close()
Eventually(stream).Should(BeClosed())
})
Context("when fed a stream of well-formed lager messages", func() {
It("should return parsed lager messages", func() {
data := lager.Data{"some-float": 3.0, "some-string": "foo"}
logger.Debug("chug", data)
logger.Info("again", data)
示例6:
var _ = Describe("Client", func() {
var (
fakeRegion aws.Region
goamzBucketClient *goamz.Bucket
bucketName string
log *gbytes.Buffer
logger lager.Logger
)
BeforeEach(func() {
bucketName = "i_am_bucket"
logger = lager.NewLogger("logger")
log = gbytes.NewBuffer()
logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))
fakeRegion = aws.Region{
Name: "fake_region",
S3Endpoint: fakeS3EndpointURL,
S3LocationConstraint: true,
}
goamzBucketClient = goamz.New(aws.Auth{}, fakeRegion).Bucket(bucketName)
})
Describe("GetOrCreateBucket", func() {
Context("when the bucket already exists", func() {
var (
err error
bucket s3.Bucket
)
示例7:
var _ = Describe("V2MessageStatusUpdater", func() {
var (
updater postal.V2MessageStatusUpdater
messagesRepo *mocks.MessagesRepository
logger lager.Logger
buffer *bytes.Buffer
conn *mocks.Connection
)
BeforeEach(func() {
conn = mocks.NewConnection()
messagesRepo = mocks.NewMessagesRepository()
buffer = bytes.NewBuffer([]byte{})
logger = lager.NewLogger("notifications")
logger.RegisterSink(lager.NewWriterSink(buffer, lager.INFO))
updater = postal.NewV2MessageStatusUpdater(messagesRepo)
})
It("updates the status of the message", func() {
updater.Update(conn, "some-message-id", "message-status", "campaign-id", logger)
Expect(messagesRepo.UpdateCall.Receives.Connection).To(Equal(conn))
Expect(messagesRepo.UpdateCall.Receives.Message).To(Equal(models.Message{
ID: "some-message-id",
Status: "message-status",
CampaignID: "campaign-id",
}))
})
示例8:
enqueue chan<- models.Task
process ifrit.Process
fakeServer *ghttp.Server
logger lager.Logger
timeout time.Duration
)
BeforeEach(func() {
timeout = 1 * time.Second
cf_http.Initialize(timeout)
fakeServer = ghttp.NewServer()
logger = lager.NewLogger("task-watcher-test")
logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))
fakeBBS = new(fake_bbs.FakeReceptorBBS)
taskWorker, enqueueTasks := task_handler.NewTaskWorkerPool(fakeBBS, logger)
enqueue = enqueueTasks
process = ifrit.Invoke(taskWorker)
})
AfterEach(func() {
fakeServer.Close()
ginkgomon.Kill(process)
})
示例9:
var _ = Describe("Mail", func() {
var (
mailServer *SMTPServer
client *mail.Client
logger lager.Logger
buffer *bytes.Buffer
config mail.Config
)
BeforeEach(func() {
var err error
buffer = &bytes.Buffer{}
logger = lager.NewLogger("notifications")
logger.RegisterSink(lager.NewWriterSink(buffer, 0))
mailServer = NewSMTPServer("user", "pass")
config = mail.Config{
User: "user",
Pass: "pass",
TestMode: false,
SkipVerifySSL: true,
DisableTLS: false,
}
config.Host, config.Port, err = net.SplitHostPort(mailServer.URL.String())
if err != nil {
panic(err)
}
示例10:
var _ = Describe("Instance Backuper", func() {
var (
providerFactory *fakes.FakeProviderFactory
redisClient *fakes.FakeRedisClient
redisBackuper *fakes.FakeRedisBackuper
redisConfigFinder *fakes.FakeRedisConfigFinder
instanceIDLocator *fakes.FakeInstanceIDLocator
backupConfig *backup.BackupConfig
logger lager.Logger
log *gbytes.Buffer
)
BeforeEach(func() {
log = gbytes.NewBuffer()
logger = lager.NewLogger("logger")
logger.RegisterSink(lager.NewWriterSink(log, lager.DEBUG))
providerFactory = new(fakes.FakeProviderFactory)
redisClient = new(fakes.FakeRedisClient)
providerFactory.RedisClientProviderReturns(redisClient, nil)
redisBackuper = new(fakes.FakeRedisBackuper)
providerFactory.RedisBackuperProviderReturns(redisBackuper)
redisConfigFinder = new(fakes.FakeRedisConfigFinder)
providerFactory.RedisConfigFinderProviderReturns(redisConfigFinder)
instanceIDLocator = new(fakes.FakeInstanceIDLocator)
providerFactory.SharedInstanceIDLocatorProviderReturns(instanceIDLocator)
providerFactory.DedicatedInstanceIDLocatorProviderReturns(instanceIDLocator)
示例11:
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Unify", func() {
var loggerA, loggerB lager.Logger
var bufferA, bufferB *bytes.Buffer
var t0, t1 time.Time
BeforeEach(func() {
loggerA = lager.NewLogger("A")
loggerB = lager.NewLogger("B")
bufferA = &bytes.Buffer{}
bufferB = &bytes.Buffer{}
loggerA.RegisterSink(lager.NewWriterSink(bufferA, lager.DEBUG))
loggerB.RegisterSink(lager.NewWriterSink(bufferB, lager.DEBUG))
bufferA.Write([]byte("non-lager-A\n"))
bufferB.Write([]byte("non-lager-B-1\n"))
loggerA.Info("A-1")
time.Sleep(10 * time.Millisecond)
t0 = time.Now()
time.Sleep(10 * time.Millisecond)
loggerB.Info("B-1")
loggerA.Info("A-2")
loggerB.Info("B-2")
loggerB.Info("B-3")