本文整理汇总了Golang中google/golang.org/grpc/grpclog.SetLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang SetLogger函数的具体用法?Golang SetLogger怎么用?Golang SetLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetLogger函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Usage = func() {
fmt.Println("Usage: quilt " +
"[-log-level=<level> | -l=<level>] [-H=<listen_address>] " +
"[log-file=<log_output_file>] " +
"[daemon | inspect <stitch> | run <stitch> | minion | " +
"stop <namespace> | get <import_path> | " +
"machines | containers | ssh <machine> | " +
"exec <container> <command> | " +
"logs <container>]")
fmt.Println("\nWhen provided a stitch, quilt takes responsibility\n" +
"for deploying it as specified. Alternatively, quilt may be\n" +
"instructed to stop all deployments in a given namespace,\n" +
"or the default namespace if none is provided.\n")
flag.PrintDefaults()
fmt.Println(" Valid logger levels are:\n" +
" debug, info, warn, error, fatal or panic.")
}
var logOut = flag.String("log-file", "", "log output file (will be overwritten)")
var logLevel = flag.String("log-level", "info", "level to set logger to")
flag.StringVar(logLevel, "l", "info", "level to set logger to")
flag.Parse()
level, err := parseLogLevel(*logLevel)
if err != nil {
fmt.Println(err)
usage()
}
log.SetLevel(level)
log.SetFormatter(util.Formatter{})
if *logOut != "" {
file, err := os.Create(*logOut)
if err != nil {
fmt.Printf("Failed to create file %s\n", *logOut)
os.Exit(1)
}
defer file.Close()
log.SetOutput(file)
}
// GRPC spews a lot of useless log messages so we tell to eat its logs, unless
// we are in debug mode
grpclog.SetLogger(l_mod.New(ioutil.Discard, "", 0))
if level == log.DebugLevel {
grpclog.SetLogger(log.StandardLogger())
}
if len(flag.Args()) == 0 {
usage()
}
subcommand := flag.Arg(0)
if quiltctl.HasSubcommand(subcommand) {
quiltctl.Run(subcommand, flag.Args()[1:])
} else {
usage()
}
}
开发者ID:NetSys,项目名称:quilt,代码行数:60,代码来源:quilt.go
示例2: getClient
// getClient returns a connection to the Suite containerd
func (cs *ContainerdSuite) getClient(socket string) error {
// Parse proto://address form addresses.
bindParts := strings.SplitN(socket, "://", 2)
if len(bindParts) != 2 {
return fmt.Errorf("bad bind address format %s, expected proto://address", socket)
}
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout(bindParts[0], bindParts[1], timeout)
}),
grpc.WithBlock(),
grpc.WithTimeout(5*time.Second),
)
conn, err := grpc.Dial(socket, dialOpts...)
if err != nil {
return err
}
healthClient := grpc_health_v1.NewHealthClient(conn)
if _, err := healthClient.Check(context.Background(), &grpc_health_v1.HealthCheckRequest{}); err != nil {
return err
}
cs.grpcClient = types.NewAPIClient(conn)
return nil
}
开发者ID:estesp,项目名称:containerd,代码行数:30,代码来源:check_test.go
示例3: RedirectGrpclog
// RedirectGrpclog will redirect grpclog to lion.
func RedirectGrpclog() {
lion.AddGlobalHook(
func(l lion.Logger) {
grpclog.SetLogger(NewLogger(l))
},
)
}
开发者ID:peter-edge,项目名称:days,代码行数:8,代码来源:grpclion.go
示例4: init
func init() {
// use go's standard logger by default like grpc
logger.mu.Lock()
logger.l = log.New(os.Stderr, "", log.LstdFlags)
grpclog.SetLogger(&logger)
logger.mu.Unlock()
}
开发者ID:40a,项目名称:bootkube,代码行数:7,代码来源:logger.go
示例5: StatsAndLogging
// StatsAndLogging constructs a Statter and an AuditLogger based on its config
// parameters, and return them both. Crashes if any setup fails.
// Also sets the constructed AuditLogger as the default logger, and configures
// the cfssl, mysql, and grpc packages to use our logger.
// This must be called before any gRPC code is called, because gRPC's SetLogger
// doesn't use any locking.
func StatsAndLogging(statConf StatsdConfig, logConf SyslogConfig) (metrics.Statter, blog.Logger) {
stats, err := metrics.NewStatter(statConf.Server, statConf.Prefix)
FailOnError(err, "Couldn't connect to statsd")
tag := path.Base(os.Args[0])
syslogger, err := syslog.Dial(
"",
"",
syslog.LOG_INFO, // default, not actually used
tag)
FailOnError(err, "Could not connect to Syslog")
syslogLevel := int(syslog.LOG_INFO)
if logConf.SyslogLevel != 0 {
syslogLevel = logConf.SyslogLevel
}
logger, err := blog.New(syslogger, logConf.StdoutLevel, syslogLevel)
FailOnError(err, "Could not connect to Syslog")
_ = blog.Set(logger)
cfsslLog.SetLogger(cfsslLogger{logger})
_ = mysql.SetLogger(mysqlLogger{logger})
grpclog.SetLogger(grpcLogger{logger})
return stats, logger
}
开发者ID:jfrazelle,项目名称:boulder,代码行数:31,代码来源:shell.go
示例6: newRootCmd
func newRootCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "helm",
Short: "The Helm package manager for Kubernetes.",
Long: globalUsage,
SilenceUsage: true,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
teardown()
},
}
p := cmd.PersistentFlags()
p.StringVar(&helmHome, "home", defaultHelmHome(), "location of your Helm config. Overrides $HELM_HOME")
p.StringVar(&tillerHost, "host", defaultHelmHost(), "address of tiller. Overrides $HELM_HOST")
p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVar(&flagDebug, "debug", false, "enable verbose output")
p.StringVar(&tillerNamespace, "tiller-namespace", defaultTillerNamespace(), "namespace of tiller")
// Tell gRPC not to log to console.
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
rup := newRepoUpdateCmd(out)
rup.Deprecated = "use 'helm repo update'\n"
cmd.AddCommand(
newCreateCmd(out),
newDeleteCmd(nil, out),
newDependencyCmd(out),
newFetchCmd(out),
newGetCmd(nil, out),
newHomeCmd(out),
newHistoryCmd(nil, out),
newInitCmd(out),
newInspectCmd(nil, out),
newInstallCmd(nil, out),
newLintCmd(out),
newListCmd(nil, out),
newPackageCmd(nil, out),
newRepoCmd(out),
newRollbackCmd(nil, out),
newSearchCmd(out),
newServeCmd(out),
newStatusCmd(nil, out),
newUpgradeCmd(nil, out),
newVerifyCmd(out),
newVersionCmd(nil, out),
newCompletionCmd(out, cmd),
// Hidden documentation generator command: 'helm docs'
newDocsCmd(out, cmd),
// Deprecated
rup,
)
// Find and add plugins
loadPlugins(cmd, helmpath.Home(homePath()), out)
return cmd
}
开发者ID:bacongobbler,项目名称:helm,代码行数:59,代码来源:helm.go
示例7: init
func init() {
var l = &log.Logger{
Out: os.Stdout,
Formatter: &log.TextFormatter{FullTimestamp: true},
Hooks: make(log.LevelHooks),
Level: log.GetLevel(),
}
grpclog.SetLogger(l)
}
开发者ID:otsimo,项目名称:watch,代码行数:9,代码来源:server.go
示例8: New
// New creates a fresh instance of libcontainerd remote.
func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("Failed to connect to containerd. Please make sure containerd is installed in your PATH or you have specificed the correct address. Got error: %v", err)
}
}()
r := &remote{
stateDir: stateDir,
daemonPid: -1,
eventTsPath: filepath.Join(stateDir, eventTimestampFilename),
pastEvents: make(map[string]*containerd.Event),
}
for _, option := range options {
if err := option.Apply(r); err != nil {
return nil, err
}
}
if err := sysinfo.MkdirAll(stateDir, 0700); err != nil {
return nil, err
}
if r.rpcAddr == "" {
r.rpcAddr = filepath.Join(stateDir, containerdSockFilename)
}
if r.startDaemon {
if err := r.runContainerdDaemon(); err != nil {
return nil, err
}
}
// don't output the grpc reconnect logging
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := append([]grpc.DialOption{grpc.WithInsecure()},
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),
)
conn, err := grpc.Dial(r.rpcAddr, dialOpts...)
if err != nil {
return nil, fmt.Errorf("error connecting to containerd: %v", err)
}
r.rpcConn = conn
r.apiClient = containerd.NewAPIClient(conn)
go r.handleConnectionChange()
if err := r.startEventsMonitor(); err != nil {
return nil, err
}
return r, nil
}
开发者ID:ungureanuvladvictor,项目名称:docker,代码行数:56,代码来源:remote_linux.go
示例9: main
func main() {
/* XXX: GRPC spews a lot of uselss log message so we tell to eat its logs.
* Once we have more sophistcated logging support, we should enable the log
* messages when in debug mode. */
grpclog.SetLogger(l_mod.New(ioutil.Discard, "", 0))
log.SetFormatter(util.Formatter{})
flag.Usage = func() {
fmt.Println("Usage: quilt [inspect <stitch> | run <stitch>" +
" | stop <namespace> | get <import_path>]" +
" [-log-level=<level> | -l=<level>]")
fmt.Println("\nWhen provided a stitch, quilt takes responsibility\n" +
"for deploying it as specified. Alternatively, quilt may be\n" +
"instructed to stop all deployments in a given namespace,\n" +
"or the default namespace if none is provided.\n")
flag.PrintDefaults()
fmt.Println(" Valid logger levels are:\n" +
" debug, info, warn, error, fatal or panic.")
}
var logLevel = flag.String("log-level", "info", "level to set logger to")
flag.StringVar(logLevel, "l", "info", "level to set logger to")
flag.Parse()
level, err := parseLogLevel(*logLevel)
if err != nil {
fmt.Println(err)
usage()
}
log.SetLevel(level)
conn := db.New()
if len(flag.Args()) != 2 {
usage()
}
switch flag.Arg(0) {
case "run":
go configLoop(conn, flag.Arg(1))
case "stop":
stop(conn, flag.Arg(1))
case "get":
getSpec(flag.Arg(1))
case "inspect":
inspect.Main(flag.Args())
return
default:
usage()
}
cluster.Run(conn)
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:53,代码来源:quilt.go
示例10: newClient
func newClient(cfg *Config) (*Client, error) {
if cfg == nil {
cfg = &Config{RetryDialer: dialEndpointList}
}
var creds *credentials.TransportAuthenticator
if cfg.TLS != nil {
c := credentials.NewTLS(cfg.TLS)
creds = &c
}
// use a temporary skeleton client to bootstrap first connection
ctx, cancel := context.WithCancel(context.TODO())
conn, err := cfg.RetryDialer(&Client{cfg: *cfg, creds: creds, ctx: ctx})
if err != nil {
return nil, err
}
client := &Client{
conn: conn,
cfg: *cfg,
creds: creds,
ctx: ctx,
cancel: cancel,
}
client.Cluster = NewCluster(client)
client.KV = NewKV(client)
client.Lease = NewLease(client)
client.Watcher = NewWatcher(client)
client.Auth = NewAuth(client)
client.Maintenance = &maintenance{c: client}
if cfg.Logger == nil {
client.logger = log.New(ioutil.Discard, "", 0)
// disable client side grpc by default
grpclog.SetLogger(log.New(ioutil.Discard, "", 0))
} else {
client.logger = cfg.Logger
grpclog.SetLogger(cfg.Logger)
}
return client, nil
}
开发者ID:oywc410,项目名称:MYPG,代码行数:39,代码来源:client.go
示例11: init
func init() {
// disable client side logs by default
logger.mu.Lock()
logger.l = log.New(ioutil.Discard, "", 0)
// logger has to override the grpclog at initialization so that
// any changes to the grpclog go through logger with locking
// instead of through SetLogger
//
// now updates only happen through settableLogger.set
grpclog.SetLogger(&logger)
logger.mu.Unlock()
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:13,代码来源:logger.go
示例12: TestMain
func TestMain(m *testing.M) {
tc = cautils.NewTestCA(nil)
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
logrus.SetOutput(ioutil.Discard)
// Set a smaller segment size so we don't incur cost preallocating
// space on old filesystems like HFS+.
wal.SegmentSizeBytes = 64 * 1024
res := m.Run()
tc.Stop()
os.Exit(res)
}
开发者ID:yongtang,项目名称:swarmkit,代码行数:14,代码来源:raft_test.go
示例13: NewGrpcTransport
// NewGrpcTransport creates a new transport
// FIXME: add TLS and configurable timeout
func NewGrpcTransport(handler TransportCallback, listenURL string) (Transport, error) {
// init a grpc transport object
trans := GrpcTransport{}
trans.clients = make(map[string]paxospb.PaxosClient)
trans.handler = handler
trans.listenURL = listenURL
// start the grpc server
trans.Start()
// stop those annoying grpc Logs
grpclog.SetLogger(&glogger{})
return &trans, nil
}
开发者ID:shaleman,项目名称:paxos,代码行数:17,代码来源:transport.go
示例14: getClient
// TODO: parse flags and pass opts
func getClient(ctx *cli.Context) types.APIClient {
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
},
))
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...)
if err != nil {
fatal(err.Error(), 1)
}
return types.NewAPIClient(conn)
}
开发者ID:carriercomm,项目名称:containerd,代码行数:16,代码来源:container.go
示例15: getClient
func getClient(address string) types.APIClient {
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(5 * time.Second)}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
},
))
conn, err := grpc.Dial(address, dialOpts...)
if err != nil {
fmt.Printf("grpc.Dial error: %v", err)
os.Exit(-1)
}
return types.NewAPIClient(conn)
}
开发者ID:hyperhq,项目名称:runv,代码行数:16,代码来源:main.go
示例16: Start
func (g *GrpcEndpoint) Start() {
lis, err := net.Listen("tcp", g.hostport)
if err != nil {
logging.Fatalf("Cannot start server on port %v. Error %v", g.hostport, err)
panic(fmt.Sprintf("Cannot start server on port %v. Error %v", g.hostport, err))
}
grpclog.SetLogger(logging.CurrentLogger())
g.grpcServer = grpc.NewServer()
// Each service should be registered
pb.RegisterQuotaServiceServer(g.grpcServer, g)
go g.grpcServer.Serve(lis)
g.currentStatus = lifecycle.Started
logging.Printf("Starting server on %v", g.hostport)
logging.Printf("Server status: %v", g.currentStatus)
}
开发者ID:maniksurtani,项目名称:quotaservice,代码行数:16,代码来源:grpc.go
示例17: getClient
// getClient returns a connection to the Suite containerd
func (cs *ContainerdSuite) getClient(socket string) error {
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
},
))
conn, err := grpc.Dial(socket, dialOpts...)
if err != nil {
return err
}
cs.grpcClient = types.NewAPIClient(conn)
return nil
}
开发者ID:carriercomm,项目名称:containerd,代码行数:18,代码来源:check_test.go
示例18: TestRaft
// Main Raft test method, we execute the
// tests sequentially to avoid any issue
// on bootstrap and raft cluster lifecycle
func TestRaft(t *testing.T) {
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
testBootstrap(t)
testLeader(t)
testLeaderDown(t)
testFollowerDown(t)
testLogReplication(t)
testLogReplicationWithoutLeader(t)
testQuorumFailure(t)
testLeaderLeave(t)
testFollowerLeave(t)
testPauseFollower(t)
// TODO
testSnapshot(t)
testRecoverSnapshot(t)
}
开发者ID:abronan,项目名称:proton,代码行数:21,代码来源:node_test.go
示例19: newCliClient
func newCliClient(address string) *cliClient {
client := &cliClient{}
dialer := func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithDialer(dialer), grpc.WithTimeout(1*time.Second))
if err != nil {
log.Fatalf("did not connect: %v\n", err)
}
client.conn = conn
client.srv = pb.NewInstanceMetaServiceClient(conn)
return client
}
开发者ID:otm,项目名称:limes,代码行数:19,代码来源:cli-client.go
示例20: connect
func (cache *rpcCache) connect(config *core.Configuration) {
// Change grpc to log using our implementation
grpclog.SetLogger(&grpcLogMabob{})
log.Info("Connecting to RPC cache at %s", config.Cache.RpcUrl)
opts := []grpc.DialOption{grpc.WithTimeout(cache.timeout)}
if config.Cache.RpcPublicKey != "" || config.Cache.RpcCACert != "" || config.Cache.RpcSecure {
auth, err := loadAuth(config.Cache.RpcCACert, config.Cache.RpcPublicKey, config.Cache.RpcPrivateKey)
if err != nil {
log.Warning("Failed to load RPC cache auth keys: %s", err)
return
}
opts = append(opts, auth)
} else {
opts = append(opts, grpc.WithInsecure())
}
connection, err := grpc.Dial(config.Cache.RpcUrl, opts...)
if err != nil {
cache.Connecting = false
log.Warning("Failed to connect to RPC cache: %s", err)
return
}
// Note that we have to actually send it a message here to validate the connection;
// Dial() only seems to return errors for superficial failures like syntactically invalid addresses,
// it will return essentially immediately even if the server doesn't exist.
healthclient := healthpb.NewHealthClient(connection)
ctx, cancel := context.WithTimeout(context.Background(), cache.timeout)
defer cancel()
resp, err := healthclient.Check(ctx, &healthpb.HealthCheckRequest{Service: "plz-rpc-cache"})
if err != nil {
cache.Connecting = false
log.Warning("Failed to contact RPC cache: %s", err)
} else if resp.Status != healthpb.HealthCheckResponse_SERVING {
cache.Connecting = false
log.Warning("RPC cache says it is not serving (%d)", resp.Status)
} else {
cache.connection = connection
cache.client = pb.NewRpcCacheClient(connection)
cache.Connected = true
cache.Connecting = false
log.Info("RPC cache connected after %0.2fs", time.Since(cache.startTime).Seconds())
}
}
开发者ID:thought-machine,项目名称:please,代码行数:42,代码来源:rpc_cache.go
注:本文中的google/golang.org/grpc/grpclog.SetLogger函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论