本文整理汇总了Golang中github.com/op/go-logging.Logger.Info方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Info方法的具体用法?Golang Logger.Info怎么用?Golang Logger.Info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/op/go-logging.Logger
的用法示例。
在下文中一共展示了Logger.Info方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoggingHandler
// HTTP logging handler
func LoggingHandler(inner http.Handler, log *logging.Logger) http.Handler{
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
sw := MakeLogger(w)
inner.ServeHTTP(sw, r)
log.Info(buildCommonLogLine(r, *r.URL, time.Now(), sw.Status(), sw.Size()))
})
}
示例2: Get
// Get executes a `go get` with a cache support.
func Get(log *log.Logger, flags *GetFlags) error {
// Check GOPATH
if gopath == "" {
return maskAny(errors.New("Specify GOPATH"))
}
gopathDir := strings.Split(gopath, string(os.PathListSeparator))[0]
// Get cache dir
cachedir, cacheIsValid, err := cache.Dir(flags.Package, cacheValid)
if err != nil {
return maskAny(err)
}
if !cacheIsValid {
// Cache has become invalid
log.Info(updating("Refreshing cache of %s"), flags.Package)
// Execute `go get` towards the cache directory
if err := runGoGet(log, flags.Package, cachedir); err != nil {
return maskAny(err)
}
}
// Sync with local gopath
if err := os.MkdirAll(gopathDir, 0777); err != nil {
return maskAny(err)
}
if err := util.ExecPrintError(nil, "rsync", "-a", filepath.Join(cachedir, srcDir), gopathDir); err != nil {
return maskAny(err)
}
return nil
}
示例3: NewRateLimiter
func NewRateLimiter(cfg config.RateLimiting, red *redis.Pool, logger *logging.Logger) (RateLimitingMiddleware, error) {
t := new(RedisSimpleRateThrottler)
t.burstSize = int64(cfg.Burst)
t.requestsPerSecond = int64(cfg.RequestsPerSecond)
t.redisPool = red
t.logger = logger
if w, err := time.ParseDuration(cfg.Window); err != nil {
return nil, err
} else {
t.window = w
}
logger.Info("Initialize rate limiter (burst size %d)", t.burstSize)
return t, nil
}
示例4: Vendor
// Get executes a `go get` with a cache support.
func Vendor(log *log.Logger, flags *VendorFlags) error {
// Get cache dir
cachedir, _, err := cache.Dir(flags.Package, time.Millisecond)
if err != nil {
return maskAny(err)
}
// Cache has become invalid
log.Info(updating("Fetching %s"), flags.Package)
// Execute `go get` towards the cache directory
if err := runGoGet(log, flags.Package, cachedir); err != nil {
return maskAny(err)
}
// Sync with vendor dir
if err := os.MkdirAll(flags.VendorDir, 0777); err != nil {
return maskAny(err)
}
if err := util.ExecPrintError(nil, "rsync", "--exclude", ".git", "-a", filepath.Join(cachedir, srcDir)+"/", flags.VendorDir); err != nil {
return maskAny(err)
}
return nil
}
示例5: Release
func Release(log *log.Logger, flags *Flags) error {
// Detect environment
hasMakefile := false
isDev := flags.ReleaseType == "dev"
if _, err := os.Stat(makefileFile); err == nil {
hasMakefile = true
log.Info("Found %s", makefileFile)
}
hasGruntfile := false
if _, err := os.Stat(gruntfileFile); err == nil {
hasGruntfile = true
log.Info("Found %s", gruntfileFile)
}
hasDockerfile := false
if _, err := os.Stat(dockerfileFile); err == nil {
hasDockerfile = true
log.Info("Found %s", dockerfileFile)
}
// Read the current version and name
info, err := GetProjectInfo()
if err != nil {
return maskAny(err)
}
log.Info("Found old version %s", info.Version)
version, err := semver.NewVersion(info.Version)
if err != nil {
return maskAny(err)
}
// Check repository state
if !isDev {
if err := checkRepoClean(log, info.GitBranch); err != nil {
return maskAny(err)
}
}
// Bump version
switch flags.ReleaseType {
case "major":
version.Major++
version.Minor = 0
version.Patch = 0
case "minor":
version.Minor++
version.Patch = 0
case "patch":
version.Patch++
case "dev":
// Do not change version
default:
return errgo.Newf("Unknown release type %s", flags.ReleaseType)
}
version.Metadata = ""
// Write new release version
if !isDev {
if err := writeVersion(log, version.String(), info.Manifests, info.GradleConfigFile, false); err != nil {
return maskAny(err)
}
}
// Build project
if hasGruntfile && !info.NoGrunt {
if _, err := os.Stat(nodeModulesFolder); os.IsNotExist(err) {
log.Info("Folder %s not found", nodeModulesFolder)
if err := util.ExecPrintError(log, "npm", "install"); err != nil {
return maskAny(err)
}
}
if err := util.ExecPrintError(log, "grunt", "build-release"); err != nil {
return maskAny(err)
}
}
if hasMakefile {
// Clean first
if !isDev {
if err := util.ExecPrintError(log, "make", info.Targets.CleanTarget); err != nil {
return maskAny(err)
}
}
// Now build
makeArgs := []string{}
if info.Targets.ReleaseTarget != "" {
makeArgs = append(makeArgs, info.Targets.ReleaseTarget)
}
if err := util.ExecPrintError(log, "make", makeArgs...); err != nil {
return maskAny(err)
}
}
if hasDockerfile {
// Build docker images
tagVersion := version.String()
if isDev {
tagVersion = strings.Replace(time.Now().Format("2006-01-02-15-04-05"), "-", "", -1)
}
//.........这里部分代码省略.........
示例6: buildDispatcher
func buildDispatcher(
startup *StartupConfig,
cfg *config.Configuration,
consul *api.Client,
handler *proxy.ProxyHandler,
rpool *redis.Pool,
logger *logging.Logger,
lastIndex uint64,
) (dispatcher.Dispatcher, uint64, error) {
var disp dispatcher.Dispatcher
var err error
var meta *api.QueryMeta
var configs api.KVPairs
var localCfg config.Configuration = *cfg
var appCfgs map[string]config.Application = make(map[string]config.Application)
dispLogger := logging.MustGetLogger("dispatch")
switch startup.DispatchingMode {
case "path":
disp, err = dispatcher.NewPathBasedDispatcher(&localCfg, dispLogger, handler)
case "host":
disp, err = dispatcher.NewHostBasedDispatcher(&localCfg, dispLogger, handler)
default:
err = fmt.Errorf("unsupported dispatching mode: '%s'", startup.DispatchingMode)
}
if err != nil {
return nil, 0, fmt.Errorf("error while creating proxy builder: %s", err)
}
applicationConfigBase := startup.ConsulBaseKey + "/applications"
queryOpts := api.QueryOptions{
WaitIndex: lastIndex,
WaitTime: 30 * time.Minute,
}
logger.Info("loading gateway config from KV %s", startup.ConsulBaseKey)
configs, meta, err = consul.KV().List(startup.ConsulBaseKey, &queryOpts)
if err != nil {
return nil, 0, err
}
for _, cfgKVPair := range configs {
logger.Debug("found KV pair with key '%s'", cfgKVPair.Key)
switch strings.TrimPrefix(startup.ConsulBaseKey+"/", cfgKVPair.Key) {
case "authentication":
if err := json.Unmarshal(cfgKVPair.Value, &localCfg.Authentication); err != nil {
return nil, meta.LastIndex, fmt.Errorf("JSON error on consul KV pair '%s': %s", cfgKVPair.Key, err)
}
case "rate_limiting":
if err := json.Unmarshal(cfgKVPair.Value, &localCfg.RateLimiting); err != nil {
return nil, meta.LastIndex, fmt.Errorf("JSON error on consul KV pair '%s': %s", cfgKVPair.Key, err)
}
}
if strings.HasPrefix(cfgKVPair.Key, applicationConfigBase) {
var appCfg config.Application
if err := json.Unmarshal(cfgKVPair.Value, &appCfg); err != nil {
return nil, meta.LastIndex, fmt.Errorf("JSON error on consul KV pair '%s': %s", cfgKVPair.Key, err)
}
name := strings.TrimPrefix(cfgKVPair.Key, applicationConfigBase+"/")
appCfgs[name] = appCfg
}
}
authHandler, err := auth.NewAuthDecorator(&localCfg.Authentication, rpool, logging.MustGetLogger("auth"), startup.UiDir)
if err != nil {
return nil, meta.LastIndex, err
}
rlim, err := ratelimit.NewRateLimiter(localCfg.RateLimiting, rpool, logging.MustGetLogger("ratelimiter"))
if err != nil {
logger.Fatal(fmt.Sprintf("error while configuring rate limiting: %s", err))
}
cch := cache.NewCache(4096)
// Order is important here! Behaviours will be called in LIFO order;
// behaviours that are added last will be called first!
disp.AddBehaviour(dispatcher.NewCachingBehaviour(cch))
disp.AddBehaviour(dispatcher.NewAuthenticationBehaviour(authHandler))
disp.AddBehaviour(dispatcher.NewRatelimitBehaviour(rlim))
for name, appCfg := range appCfgs {
logger.Info("registering application '%s' from Consul", name)
if err := disp.RegisterApplication(name, appCfg); err != nil {
return nil, meta.LastIndex, err
}
}
for name, appCfg := range localCfg.Applications {
logger.Info("registering application '%s' from local config", name)
if err := disp.RegisterApplication(name, appCfg); err != nil {
return nil, meta.LastIndex, err
}
}
//.........这里部分代码省略.........