当前位置: 首页>>代码示例>>Golang>>正文


Golang Logger.Infof方法代码示例

本文整理汇总了Golang中github.com/Sirupsen/logrus.Logger.Infof方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Infof方法的具体用法?Golang Logger.Infof怎么用?Golang Logger.Infof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Sirupsen/logrus.Logger的用法示例。


在下文中一共展示了Logger.Infof方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: runMigrations

func runMigrations(config *app.Config, logger *logrus.Logger) {
	logger.Infof("running migrations in '%s'...", config.DbFile)
	migrator, err := app.NewMigratable(config, logger)
	if err != nil {
		logger.Fatal(err.Error())
	}
	err = migrator.Migrate()
	if err != nil {
		logger.Fatal(err.Error())
	}
}
开发者ID:seesawlabs,项目名称:ivan-kirichenko-exercise,代码行数:11,代码来源:main.go

示例2: ParseLicenses

// ParseLicenses returns an error if the license
// file is corrupted
func ParseLicenses(lfile string, stream *logrus.Logger) ([]string, error) {
	ret := []string{}
	blank := []string{}

	// If it exists, check that the last
	f, err := os.Open(lfile)
	if err != nil {
		return ret, fmt.Errorf("Error trying to open license file %s: %v", lfile, err)
	}
	defer f.Close()

	stream.Infof("Extracting licenses from %s", lfile)

	reader := bufio.NewReader(f)

	process := func(r io.Reader) (string, error) {
		line, err := reader.ReadString('\n')
		if err != nil {
			return "", err
		}
		stream.Infof("  Raw line: '%s'", line)
		t := strings.Trim(line, "\n")
		stream.Infof("  Trimmed line: '%s'", t)
		return t, nil
	}

	line, err := process(reader)
	if err == io.EOF {
		return ret, nil
	}
	if err != nil {
		return blank, err
	}
	if line != "" {
		ret = append(ret, line)
	}
	for err == nil {
		line, err := process(reader)
		if err == io.EOF {
			return ret, nil
		}
		if err != nil {
			return blank, err
		}
		if line != "" {
			ret = append(ret, line)
		}
	}
	return blank, fmt.Errorf("License file corrupted, ended with %s", line)
}
开发者ID:xogeny,项目名称:soupnazi,代码行数:52,代码来源:licenses.go

示例3: AddLicense

func AddLicense(lic string, stream *logrus.Logger) error {
	token := RawToken(lic)

	if token == nil {
		return fmt.Errorf("License %s is not a valid JWT", lic)
	} else {
		stream.Debugf("License passed syntax checking: %v", token)
	}

	lfile := LicenseFile()
	if lfile == "" {
		return fmt.Errorf("Unable to identify settings file")
	}

	stream.Infof("License file location: %s", lfile)

	// If file doesn't exist, "touch" it
	if _, err := os.Stat(lfile); os.IsNotExist(err) {
		pdir := path.Dir(lfile)
		if pdir == "" {
			return fmt.Errorf("Could't determine parent directory of %s: %v", lfile, err)
		}

		stream.Infof("  Creating parent directories")
		err := os.MkdirAll(pdir, 0777)
		if err != nil {
			return fmt.Errorf("Could't create parent directory %s: %v", pdir, err)
		}

		stream.Infof("  Creating license file")
		f, err := os.Create(lfile)
		if err != nil {
			return fmt.Errorf("Error trying create new licenses file at %s: %v", lfile, err)
		}
		f.Close()
	}

	lics, err := ParseLicenses(lfile, stream)
	if err != nil {
		return fmt.Errorf("License file at %s is corrupted: %v")
	}

	// Check for duplicates
	for _, l := range lics {
		if lic == l {
			stream.Infof("  Not adding '%s' because it is a duplicate of an existing entry", l)
			return nil
		}
	}

	f, err := os.OpenFile(lfile, os.O_RDWR, 0777)
	if err != nil {
		return fmt.Errorf("Error trying to open license file %s: %v", lfile, err)
	}

	_, err = f.Seek(0, 2)
	if err != nil {
		return fmt.Errorf("Error seeking end of license file %s: %v", lfile, err)
	}

	_, err = f.Write([]byte(fmt.Sprintf("%s\n", lic)))
	if err != nil {
		return fmt.Errorf("Error writing license to %s: %v", lfile, err)
	}

	return nil
}
开发者ID:xogeny,项目名称:soupnazi,代码行数:67,代码来源:licenses.go

示例4: GenerateNodeLocked

func GenerateNodeLocked(details NodeLocked, stream *logrus.Logger) (string, error) {
	// Create the token
	token := jwt.New(jwt.SigningMethodHS256)

	key := KeyHash(details.Secret)

	// Set some claims
	token.Claims["app"] = details.Application
	token.Claims["f"] = details.Feature

	mins := details.Minutes

	stream.Infof("Generating token:")

	// If a negative number was explicitly provided, no expiration is
	// specified.  Otherwise, the details.Days parameter is the number
	// of days until expiration
	if mins < 0 {
		stream.Infof("  Token will never expire")
	} else {
		dur := time.Minute * time.Duration(mins)
		exp := time.Now().Add(dur)
		token.Claims["exp"] = exp.Unix()
		stream.Infof("  Token will expire in: %s", dur.String())
		stream.Infof("    (on %v)", exp.Format(time.UnixDate))
	}

	if details.MAC == "*" {
		stream.Infof("  Token will work for: any MAC address")
	} else {
		stream.Infof("  Token will only work for MAC address: %s", details.MAC)
		token.Claims["a"] = details.MAC
	}

	pstr := ""
	sep := ""
	for k, v := range details.Params {
		pstr = pstr + sep + k + "=" + v
		sep = ", "
	}

	stream.Infof("  Params: %s", pstr)
	if len(details.Params) > 0 {
		token.Claims["p"] = details.Params
	}

	stream.Infof("  Claims: %v", token.Claims)

	// Sign and get the complete encoded token as a string
	tokenString, err := token.SignedString([]byte(key))

	if err == nil {
		stream.Infof("  Token: %s", tokenString)
	} else {
		stream.Infof("  Error creating token: %v", err)
	}

	return tokenString, err
}
开发者ID:xogeny,项目名称:soupnazi,代码行数:59,代码来源:gen.go


注:本文中的github.com/Sirupsen/logrus.Logger.Infof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。