本文整理匯總了Golang中loggregator/sinks.NewSyslogSink函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewSyslogSink函數的具體用法?Golang NewSyslogSink怎麽用?Golang NewSyslogSink使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewSyslogSink函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDrainForReturnsOnly
func TestDrainForReturnsOnly(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
sink1 := sinks.NewSyslogSink(target, "other sink", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
sink2 := sinks.NewSyslogSink(target, "sink we are searching for", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
sinkDrain := groupedSinks.DrainFor(target, "sink we are searching for")
assert.Equal(t, sink2, sinkDrain)
}
示例2: TestDumpForReturnsOnyDumps
func TestDumpForReturnsOnyDumps(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
sink3 := sinks.NewDumpSink(target, 5, loggertesthelper.Logger(), make(chan sinks.Sink, 1), time.Second)
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
groupedSinks.Register(sink3)
appSink := groupedSinks.DumpFor(target)
assert.Equal(t, appSink, sink3)
}
示例3: TestDumpForReturnsOnyDumps
func TestDumpForReturnsOnyDumps(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), syslogWriter)
sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), syslogWriter)
sink3 := sinks.NewDumpSink(target, 5, loggertesthelper.Logger())
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
groupedSinks.Register(sink3)
appSink := groupedSinks.DumpFor(target)
assert.Equal(t, appSink, sink3)
}
示例4: TestDelete
func TestDelete(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
groupedSinks.Delete(sink1)
appSinks := groupedSinks.For(target)
assert.Equal(t, len(appSinks), 1)
assert.Equal(t, appSinks[0], sink2)
}
示例5: registerDrainUrls
func (sinkServer *sinkServer) registerDrainUrls(appId string, drainUrls []string) {
if len(drainUrls) == 0 {
for _, sink := range sinkServer.drainUrlsForApps[appId] {
sinkServer.activeSinksChans.Delete(sink.Channel())
close(sink.Channel())
}
delete(sinkServer.drainUrlsForApps, appId)
return
}
if sinkServer.drainUrlsForApps[appId] == nil {
sinkServer.drainUrlsForApps[appId] = make(map[string]sinks.Sink, len(drainUrls))
}
for _, sink := range sinkServer.drainUrlsForApps[appId] {
if contains(sink.Identifier(), drainUrls) {
continue
}
sinkServer.activeSinksChans.Delete(sink.Channel())
close(sink.Channel())
delete(sinkServer.drainUrlsForApps[appId], sink.Identifier())
}
for _, drainUrl := range drainUrls {
if sinkServer.drainUrlsForApps[appId][drainUrl] == nil {
s, err := sinks.NewSyslogSink(appId, drainUrl, sinkServer.logger)
if err != nil {
sinkServer.logger.Error(err.Error())
continue
}
go s.Run(sinkServer.sinkCloseChan)
sinkServer.activeSinksChans.Register(s.Channel(), appId)
sinkServer.drainUrlsForApps[appId][drainUrl] = s
}
}
}
示例6: TestDrainsFor
func TestDrainsFor(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
otherTarget := "790"
sink1 := sinks.NewDumpSink(target, 10, loggertesthelper.Logger(), make(chan sinks.Sink, 1), time.Second)
sink2 := sinks.NewSyslogSink(target, "url", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
sink3 := sinks.NewSyslogSink(otherTarget, "url", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
groupedSinks.Register(sink3)
appSinks := groupedSinks.DrainsFor(target)
assert.Equal(t, len(appSinks), 1)
assert.Equal(t, appSinks[0], sink2)
}
示例7: TestDrainsFor
func TestDrainsFor(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
otherTarget := "790"
sink1 := sinks.NewDumpSink(target, 10, loggertesthelper.Logger())
sink2 := sinks.NewSyslogSink(target, "url", loggertesthelper.Logger(), syslogWriter)
sink3 := sinks.NewSyslogSink(otherTarget, "url", loggertesthelper.Logger(), syslogWriter)
groupedSinks.Register(sink1)
groupedSinks.Register(sink2)
groupedSinks.Register(sink3)
appSinks := groupedSinks.DrainsFor(target)
assert.Equal(t, len(appSinks), 1)
assert.Equal(t, appSinks[0], sink2)
}
示例8: TestRegisterReturnsFalseForEmptyIdentifier
func TestRegisterReturnsFalseForEmptyIdentifier(t *testing.T) {
groupedSinks := NewGroupedSinks()
appId := "appId"
appSink := sinks.NewSyslogSink(appId, "", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
result := groupedSinks.Register(appSink)
assert.False(t, result)
}
示例9: TestRegisterReturnsFalseForEmptyIdentifier
func TestRegisterReturnsFalseForEmptyIdentifier(t *testing.T) {
groupedSinks := NewGroupedSinks()
appId := "appId"
appSink := sinks.NewSyslogSink(appId, "", loggertesthelper.Logger(), syslogWriter)
result := groupedSinks.Register(appSink)
assert.False(t, result)
}
示例10: TestRegisterReturnsFalseWhenAttemptingToAddADuplicateSink
func TestRegisterReturnsFalseWhenAttemptingToAddADuplicateSink(t *testing.T) {
groupedSinks := NewGroupedSinks()
appId := "789"
appSink := sinks.NewSyslogSink(appId, "url", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
groupedSinks.Register(appSink)
result := groupedSinks.Register(appSink)
assert.False(t, result)
}
示例11: TestDumpForReturnsNilIfThereIsNone
func TestDumpForReturnsNilIfThereIsNone(t *testing.T) {
groupedSinks := NewGroupedSinks()
target := "789"
sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
groupedSinks.Register(sink1)
appSink := groupedSinks.DumpFor(target)
assert.Nil(t, appSink)
}
示例12: TestRegisterAndFor
func TestRegisterAndFor(t *testing.T) {
groupedSinks := NewGroupedSinks()
appId := "789"
appSink := sinks.NewSyslogSink(appId, "url", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
result := groupedSinks.Register(appSink)
appSinks := groupedSinks.For(appId)
assert.True(t, result)
assert.Equal(t, len(appSinks), 1)
assert.Equal(t, appSinks[0], appSink)
}
示例13: manageDrains
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceName string) {
if sourceName != "App" {
return
}
//delete all drains for app
if len(drainUrls) == 0 {
for _, sink := range activeSinks.DrainsFor(appId) {
messageRouter.unregisterSink(sink, activeSinks)
}
return
}
//delete all drains that were not sent
for _, sink := range activeSinks.DrainsFor(appId) {
if contains(sink.Identifier(), drainUrls) {
continue
}
messageRouter.unregisterSink(sink, activeSinks)
}
//add all drains that didn't exist
for _, drainUrl := range drainUrls {
if activeSinks.DrainFor(appId, drainUrl) == nil && !messageRouter.urlIsBlackListed(drainUrl) {
dl, err := url.Parse(drainUrl)
if err != nil {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMessage := fmt.Sprintf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
continue
}
ipNotBlacklisted, err := iprange.IpOutsideOfRanges(*dl, messageRouter.blackListIPs)
if err != nil {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMessage := fmt.Sprintf("MessageRouter: Error when trying to check syslog url %v against blacklist ip ranges. Requesting close. Err: %v", drainUrl, err)
messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
continue
}
if ipNotBlacklisted {
sysLogger := sinks.NewSyslogWriter(dl.Scheme, dl.Host, appId, messageRouter.skipCertVerify)
s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger, messageRouter.errorChannel)
ok := messageRouter.registerSink(s, activeSinks)
if ok {
go s.Run()
}
} else {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMsg := fmt.Sprintf("MessageRouter: Syslog drain url is blacklisted: %s", drainUrl)
messageRouter.sendLoggregatorErrorMessage(errorMsg, appId)
}
}
}
}
示例14: registerNewSyslogSinks
func (sinkManager *SinkManager) registerNewSyslogSinks(appId string, syslogSinkUrls []string) {
for _, syslogSinkUrl := range syslogSinkUrls {
if sinkManager.sinks.DrainFor(appId, syslogSinkUrl) == nil && !sinkManager.urlBlacklistManager.IsBlacklisted(syslogSinkUrl) {
parsedSyslogDrainUrl, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkUrl)
if err != nil {
sinkManager.urlBlacklistManager.BlacklistUrl(syslogSinkUrl)
errorMsg := fmt.Sprintf("SinkManager: Invalid syslog drain URL: %s. Err: %v", syslogSinkUrl, err)
sinkManager.sendSyslogErrorToLoggregator(errorMsg, appId)
} else {
syslogWriter := syslogwriter.NewSyslogWriter(parsedSyslogDrainUrl.Scheme, parsedSyslogDrainUrl.Host, appId, sinkManager.skipCertVerify)
syslogSink := sinks.NewSyslogSink(appId, syslogSinkUrl, sinkManager.logger, syslogWriter, sinkManager.errorChannel)
if sinkManager.RegisterSink(syslogSink) {
go syslogSink.Run()
}
}
}
}
}
示例15: manageDrains
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceType logmessage.LogMessage_SourceType) {
if sourceType != logmessage.LogMessage_WARDEN_CONTAINER {
return
}
//delete all drains for app
if len(drainUrls) == 0 {
for _, sink := range activeSinks.DrainsFor(appId) {
messageRouter.unregisterSink(sink, activeSinks)
}
return
}
//delete all drains that were not sent
for _, sink := range activeSinks.DrainsFor(appId) {
if contains(sink.Identifier(), drainUrls) {
continue
}
messageRouter.unregisterSink(sink, activeSinks)
}
//add all drains that didn't exist
for _, drainUrl := range drainUrls {
if activeSinks.DrainFor(appId, drainUrl) == nil {
dl, err := url.Parse(drainUrl)
if err != nil {
messageRouter.logger.Warnf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
continue
}
sysLogger := sinks.NewSyslogWriter("tcp", dl.Host, appId)
s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger)
ok := messageRouter.registerSink(s, activeSinks)
if ok {
go s.Run()
}
}
}
}