本文整理汇总了Golang中github.com/cloudfoundry/gorouter/common.NewLogCounter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogCounter函数的具体用法?Golang NewLogCounter怎么用?Golang NewLogCounter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLogCounter函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("router.main")
err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
if err != nil {
logger.Errorf("Dropsonde failed to initialize: %s", err.Error())
os.Exit(1)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
if c.DebugAddr != "" {
cf_debug_server.Run(c.DebugAddr)
}
logger.Info("Setting up NATs connection")
natsClient := connectToNatsServer(c, logger)
registry := rregistry.NewRouteRegistry(c, natsClient)
logger.Info("Setting up routing_api route fetcher")
setupRouteFetcher(c, registry)
varz := rvarz.NewVarz(registry)
accessLogger, err := access_log.CreateRunningAccessLogger(c)
if err != nil {
logger.Fatalf("Error creating access logger: %s\n", err)
}
proxy := buildProxy(c, registry, accessLogger, varz)
router, err := router.NewRouter(c, proxy, natsClient, registry, varz, logCounter)
if err != nil {
logger.Errorf("An error occurred: %s", err.Error())
os.Exit(1)
}
errChan := router.Run()
logger.Info("gorouter.started")
waitOnErrOrSignal(c, logger, errChan, router)
os.Exit(0)
}
开发者ID:simonjohansson,项目名称:gorouter,代码行数:57,代码来源:main.go
示例2:
BeforeEach(func() {
natsPort = test_util.NextAvailPort()
natsRunner = natsrunner.NewNATSRunner(int(natsPort))
natsRunner.Start()
proxyPort := test_util.NextAvailPort()
statusPort := test_util.NextAvailPort()
config = test_util.SpecConfig(natsPort, statusPort, proxyPort)
config.EndpointTimeout = 5 * time.Second
mbusClient = natsRunner.MessageBus.(*yagnats.Client)
registry = rregistry.NewRouteRegistry(config, mbusClient)
varz = vvarz.NewVarz(registry)
logcounter := vcap.NewLogCounter()
proxy := proxy.NewProxy(proxy.ProxyArgs{
EndpointTimeout: config.EndpointTimeout,
Ip: config.Ip,
TraceKey: config.TraceKey,
Registry: registry,
Reporter: varz,
AccessLogger: &access_log.NullAccessLogger{},
})
r, err := NewRouter(config, proxy, mbusClient, registry, varz, logcounter)
Ω(err).ShouldNot(HaveOccurred())
router = r
r.Run()
})
AfterEach(func() {
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:30,代码来源:router_drain_test.go
示例3: main
func main() {
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("router.main")
err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
if err != nil {
logger.Errorf("Dropsonde failed to initialize: %s", err.Error())
os.Exit(1)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
if c.DebugAddr != "" {
cf_debug_server.Run(c.DebugAddr)
}
natsServers := c.NatsServers()
var natsClient yagnats.NATSConn
attempts := 3
for attempts > 0 {
natsClient, err = yagnats.Connect(natsServers)
if err == nil {
break
} else {
attempts--
time.Sleep(100 * time.Millisecond)
}
}
if err != nil {
logger.Errorf("Error connecting to NATS: %s\n", err)
os.Exit(1)
}
natsClient.AddClosedCB(func(conn *nats.Conn) {
logger.Errorf("Close on NATS client. nats.Conn: %+v", *conn)
os.Exit(1)
})
registry := rregistry.NewRouteRegistry(c, natsClient)
if c.RoutingApiEnabled() {
logger.Info("Setting up routing_api route fetcher")
tokenFetcher := token_fetcher.NewTokenFetcher(&c.OAuth)
routingApiUri := fmt.Sprintf("%s:%d", c.RoutingApi.Uri, c.RoutingApi.Port)
routingApiClient := routing_api.NewClient(routingApiUri)
routeFetcher := route_fetcher.NewRouteFetcher(steno.NewLogger("router.route_fetcher"), tokenFetcher, registry, c, routingApiClient, 1)
routeFetcher.StartFetchCycle()
routeFetcher.StartEventCycle()
}
varz := rvarz.NewVarz(registry)
accessLogger, err := access_log.CreateRunningAccessLogger(c)
if err != nil {
logger.Fatalf("Error creating access logger: %s\n", err)
}
args := proxy.ProxyArgs{
EndpointTimeout: c.EndpointTimeout,
Ip: c.Ip,
TraceKey: c.TraceKey,
Registry: registry,
Reporter: varz,
AccessLogger: accessLogger,
SecureCookies: c.SecureCookies,
}
p := proxy.NewProxy(args)
router, err := router.NewRouter(c, p, natsClient, registry, varz, logCounter)
if err != nil {
logger.Errorf("An error occurred: %s", err.Error())
os.Exit(1)
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
errChan := router.Run()
logger.Info("gorouter.started")
select {
case err := <-errChan:
if err != nil {
logger.Errorf("Error occurred: %s", err.Error())
os.Exit(1)
}
case sig := <-signals:
go func() {
//.........这里部分代码省略.........
开发者ID:trainchou,项目名称:gorouter,代码行数:101,代码来源:main.go
示例4: init
package log
import (
"github.com/cloudfoundry/gorouter/common"
"github.com/cloudfoundry/gorouter/config"
steno "github.com/cloudfoundry/gosteno"
"os"
)
var logger *steno.Logger
var Counter = common.NewLogCounter()
func init() {
stenoConfig := &steno.Config{
Sinks: []steno.Sink{steno.NewIOSink(os.Stderr)},
Codec: steno.NewJsonCodec(),
Level: steno.LOG_ALL,
}
steno.Init(stenoConfig)
logger = steno.NewLogger("router.init")
}
func SetupLoggerFromConfig(c *config.Config) {
l, err := steno.GetLogLevel(c.Logging.Level)
if err != nil {
panic(err)
}
s := make([]steno.Sink, 0)
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:31,代码来源:logger.go
示例5: main
func main() {
flag.StringVar(&configFile, "c", "", "Configuration File")
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("router.main")
err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
if err != nil {
logger.Errorf("Dropsonde failed to initialize: %s", err.Error())
os.Exit(1)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
if c.DebugAddr != "" {
cf_debug_server.Run(c.DebugAddr)
}
logger.Info("Setting up NATs connection")
natsClient := connectToNatsServer(logger, c)
metricsReporter := metrics.NewMetricsReporter()
registry := rregistry.NewRouteRegistry(c, natsClient, metricsReporter)
varz := rvarz.NewVarz(registry)
compositeReporter := metrics.NewCompositeReporter(varz, metricsReporter)
accessLogger, err := access_log.CreateRunningAccessLogger(c)
if err != nil {
logger.Fatalf("Error creating access logger: %s\n", err)
}
var crypto secure.Crypto
var cryptoPrev secure.Crypto
if c.RouteServiceEnabled {
crypto = createCrypto(logger, c.RouteServiceSecret)
if c.RouteServiceSecretPrev != "" {
cryptoPrev = createCrypto(logger, c.RouteServiceSecretPrev)
}
}
proxy := buildProxy(c, registry, accessLogger, compositeReporter, crypto, cryptoPrev)
router, err := router.NewRouter(c, proxy, natsClient, registry, varz, logCounter, nil)
if err != nil {
logger.Errorf("An error occurred: %s", err.Error())
os.Exit(1)
}
members := grouper.Members{
{"router", router},
}
if c.RoutingApiEnabled() {
logger.Info("Setting up route fetcher")
routeFetcher := setupRouteFetcher(logger, c, registry)
members = append(members, grouper.Member{"router-fetcher", routeFetcher})
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1))
err = <-monitor.Wait()
if err != nil {
logger.Error("gorouter.exited-with-failure")
os.Exit(1)
}
os.Exit(0)
}
开发者ID:idouba,项目名称:gorouter,代码行数:82,代码来源:main.go
示例6: main
func main() {
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
InitLoggerFromConfig(c, logCounter)
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("router.main")
natsMembers := make([]string, len(c.Nats))
for _, info := range c.Nats {
uri := url.URL{
Scheme: "nats",
User: url.UserPassword(info.User, info.Pass),
Host: fmt.Sprintf("%s:%d", info.Host, info.Port),
}
natsMembers = append(natsMembers, uri.String())
}
natsClient := yagnats.NewApceraClientWrapper(natsMembers)
err := natsClient.Connect()
if err != nil {
logger.Fatalf("Error connecting to NATS: %s\n", err)
}
registry := rregistry.NewRouteRegistry(c, natsClient)
varz := rvarz.NewVarz(registry)
accessLogger, err := access_log.CreateRunningAccessLogger(c)
if err != nil {
logger.Fatalf("Error creating access logger: %s\n", err)
}
args := proxy.ProxyArgs{
EndpointTimeout: c.EndpointTimeout,
Ip: c.Ip,
TraceKey: c.TraceKey,
Registry: registry,
Reporter: varz,
AccessLogger: accessLogger,
}
p := proxy.NewProxy(args)
router, err := router.NewRouter(c, p, natsClient, registry, varz, logCounter)
if err != nil {
logger.Errorf("An error occurred: %s", err.Error())
os.Exit(1)
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
errChan := router.Run()
logger.Info("gorouter.started")
select {
case err := <-errChan:
if err != nil {
logger.Errorf("Error occurred: %s", err.Error())
os.Exit(1)
}
case sig := <-signals:
go func() {
for sig := range signals {
logger.Infod(
map[string]interface{}{
"signal": sig.String(),
},
"gorouter.signal.ignored",
)
}
}()
if sig == syscall.SIGUSR1 {
logger.Infod(
map[string]interface{}{
"timeout": (c.DrainTimeout).String(),
},
"gorouter.draining",
)
router.Drain(c.DrainTimeout)
}
stoppingAt := time.Now()
logger.Info("gorouter.stopping")
router.Stop()
//.........这里部分代码省略.........
开发者ID:johannespetzold,项目名称:gorouter,代码行数:101,代码来源:main.go
示例7: main
func main() {
flag.StringVar(&configFile, "c", "", "Configuration File")
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
prefix := "gorouter.stdout"
if c.Logging.Syslog != "" {
prefix = c.Logging.Syslog
}
logger, _ := cf_lager.New(prefix)
InitLoggerFromConfig(logger, c, logCounter)
err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
if err != nil {
logger.Fatal("dropsonde-initialize-error", err)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
if c.DebugAddr != "" {
cf_debug_server.Run(c.DebugAddr)
}
logger.Info("setting-up-nats-connection")
natsClient := connectToNatsServer(logger.Session("nats"), c)
metricsReporter := metrics.NewMetricsReporter()
registry := rregistry.NewRouteRegistry(logger.Session("registry"), c, natsClient, metricsReporter)
varz := rvarz.NewVarz(registry)
compositeReporter := metrics.NewCompositeReporter(varz, metricsReporter)
accessLogger, err := access_log.CreateRunningAccessLogger(logger.Session("access-log"), c)
if err != nil {
logger.Fatal("error-creating-access-logger", err)
}
var crypto secure.Crypto
var cryptoPrev secure.Crypto
if c.RouteServiceEnabled {
crypto = createCrypto(logger, c.RouteServiceSecret)
if c.RouteServiceSecretPrev != "" {
cryptoPrev = createCrypto(logger, c.RouteServiceSecretPrev)
}
}
proxy := buildProxy(logger.Session("proxy"), c, registry, accessLogger, compositeReporter, crypto, cryptoPrev)
router, err := router.NewRouter(logger.Session("router"), c, proxy, natsClient, registry, varz, logCounter, nil)
if err != nil {
logger.Fatal("initialize-router-error", err)
}
members := grouper.Members{
{"router", router},
}
if c.RoutingApiEnabled() {
logger.Info("setting-up-routing-api")
routeFetcher := setupRouteFetcher(logger.Session("route-fetcher"), c, registry)
// check connectivity to routing api
err := routeFetcher.FetchRoutes()
if err != nil {
logger.Fatal("routing-api-connection-failed", err)
}
members = append(members, grouper.Member{"router-fetcher", routeFetcher})
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1))
err = <-monitor.Wait()
if err != nil {
logger.Error("gorouter.exited-with-failure", err)
os.Exit(1)
}
os.Exit(0)
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:90,代码来源:main.go
注:本文中的github.com/cloudfoundry/gorouter/common.NewLogCounter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论