本文整理汇总了Golang中github.com/qiniu/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newCacheService
func newCacheService() {
CacheAdapter = Cfg.MustValue("cache", "ADAPTER", "memory")
if EnableRedis {
log.Info("Redis Enabled")
}
if EnableMemcache {
log.Info("Memcache Enabled")
}
switch CacheAdapter {
case "memory":
CacheConfig = fmt.Sprintf(`{"interval":%d}`, Cfg.MustInt("cache", "INTERVAL", 60))
case "redis", "memcache":
CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
default:
qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter)
}
var err error
Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
if err != nil {
qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n",
CacheAdapter, CacheConfig, err)
}
log.Info("Cache Service Enabled")
}
示例2: main
func main() {
configfn := "nameserver.conf"
data, err := ioutil.ReadFile(configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", configfn, err)
}
server := NewServer()
for i, v := range conf.Disks {
log.Infof("Adding %v to disks", v)
server.registeredDisks = append(server.registeredDisks, &conf.Disks[i])
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
s := grpc.NewServer()
pb.RegisterNameServer(s, server)
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
示例3: LoadRepoConfig
func LoadRepoConfig() {
workDir, err := base.ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
cfgPath := filepath.Join(workDir, "conf", t)
files, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
}
cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
if com.IsDir(cfgPath) {
customFiles, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
LanguageIgns = typeFiles[0]
Licenses = typeFiles[1]
}
示例4: newLogService
func newLogService() {
log.Info("%s %s", AppName, AppVer)
// Get and check log mode.
LogModes = strings.Split(Cfg.MustValue("log", "MODE", "console"), ",")
LogConfigs = make([]string, len(LogModes))
for i, mode := range LogModes {
mode = strings.TrimSpace(mode)
modeSec := "log." + mode
if _, err := Cfg.GetSection(modeSec); err != nil {
qlog.Fatalf("Unknown log mode: %s\n", mode)
}
// Log level.
levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace")
level, ok := logLevels[levelName]
if !ok {
qlog.Fatalf("Unknown log level: %s\n", levelName)
}
// Generate log configuration.
switch mode {
case "console":
LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
case "file":
logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log")
os.MkdirAll(path.Dir(logPath), os.ModePerm)
LogConfigs[i] = fmt.Sprintf(
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
logPath,
Cfg.MustBool(modeSec, "LOG_ROTATE", true),
Cfg.MustInt(modeSec, "MAX_LINES", 1000000),
1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)),
Cfg.MustBool(modeSec, "DAILY_ROTATE", true),
Cfg.MustInt(modeSec, "MAX_DAYS", 7))
case "conn":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false),
Cfg.MustBool(modeSec, "RECONNECT", false),
Cfg.MustValue(modeSec, "PROTOCOL", "tcp"),
Cfg.MustValue(modeSec, "ADDR", ":7020"))
case "smtp":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
Cfg.MustValue(modeSec, "USER", "[email protected]"),
Cfg.MustValue(modeSec, "PASSWD", "******"),
Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"),
Cfg.MustValue(modeSec, "RECEIVERS", "[]"),
Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve"))
case "database":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level,
Cfg.MustValue(modeSec, "Driver"),
Cfg.MustValue(modeSec, "CONN"))
}
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, LogConfigs[i])
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
}
}
示例5: main
func main() {
configfn := flag.String("config", "default.conf", "location of configuration file")
flag.Parse()
data, err := ioutil.ReadFile(*configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", *configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", *configfn, err)
}
// default is that cfs is bootstrapped using docker
cname, err := detectDockerContainer()
if err != nil {
log.Printf("server: failed to detect docker container (%v)", err)
} else {
stats.SetContainerName(cname)
log.Printf("server: detect docker container %q", cname)
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
cfs := NewServer()
for _, d := range conf.Disks {
err = cfs.AddDisk(d.Name, d.Root)
if err != nil {
log.Fatalf("server: failed to add disk (%v)", err)
}
}
// 0x1234 is the client ID for cfsctl, and its quota is 10 req/sec.
enforce.SetQuota(0x1234, 10)
// TODO report with influxSinker
stats.Report(nil, 3*time.Second)
s := grpc.NewServer()
pb.RegisterCfsServer(s, cfs)
pb.RegisterStatsServer(s, stats.Server())
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
示例6: init
func init() {
var err error
if appPath, err = exePath(); err != nil {
qlog.Fatalf("publickey.init(fail to get app path): %v\n", err)
}
// Determine and create .ssh path.
SshPath = filepath.Join(homeDir(), ".ssh")
if err = os.MkdirAll(SshPath, os.ModePerm); err != nil {
qlog.Fatalf("publickey.init(fail to create SshPath(%s)): %v\n", SshPath, err)
}
}
示例7: NewRepoContext
func NewRepoContext() {
zip.Verbose = false
// Check if server has basic git setting.
stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
if strings.Contains(stderr, "fatal:") {
qlog.Fatalf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.email", "[email protected]"); err != nil {
qlog.Fatalf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
} else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
qlog.Fatalf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
}
}
}
示例8: newSessionService
func newSessionService() {
SessionProvider = Cfg.MustValue("session", "PROVIDER", "memory")
SessionConfig = new(session.Config)
SessionConfig.ProviderConfig = Cfg.MustValue("session", "PROVIDER_CONFIG")
SessionConfig.CookieName = Cfg.MustValue("session", "COOKIE_NAME", "i_like_gogits")
SessionConfig.CookieSecure = Cfg.MustBool("session", "COOKIE_SECURE")
SessionConfig.EnableSetCookie = Cfg.MustBool("session", "ENABLE_SET_COOKIE", true)
SessionConfig.GcIntervalTime = Cfg.MustInt64("session", "GC_INTERVAL_TIME", 86400)
SessionConfig.SessionLifeTime = Cfg.MustInt64("session", "SESSION_LIFE_TIME", 86400)
SessionConfig.SessionIDHashFunc = Cfg.MustValue("session", "SESSION_ID_HASHFUNC", "sha1")
SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY")
if SessionProvider == "file" {
os.MkdirAll(path.Dir(SessionConfig.ProviderConfig), os.ModePerm)
}
var err error
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
if err != nil {
qlog.Fatalf("Init session system failed, provider: %s, %v\n",
SessionProvider, err)
}
log.Info("Session Service Enabled")
}
示例9: Send
func (s *httpSender) Send(events []Event) error {
if len(events) == 0 {
return nil
} else if len(events) > MaxBatchSize {
return ErrTooManyEvents
}
pr, pw := io.Pipe()
go func() {
err := json.NewEncoder(pw).Encode(events)
pw.CloseWithError(err)
}()
defer pr.Close()
req, err := http.NewRequest("POST", s.remote, pr)
if err != nil {
log.Fatalf("http.NewRequest %s failed - %v", s.remote, err)
}
req.Header.Add("Content-type", "application/json; charset=UTF-8")
resp, err := s.http.Do(req)
if err != nil {
return &httpErr{err, 0}
} else if resp.StatusCode != 200 {
return &httpErr{nil, resp.StatusCode}
}
defer resp.Body.Close()
return nil
}
示例10: setUpClient
func setUpClient() *client.Client {
// Set up a connection to the server.
c, err := client.New(address)
if err != nil {
log.Fatalf("Cannot create cfs client: %v", err)
}
return c
}
示例11: actionStartServer
func actionStartServer(c *cli.Context) error {
suv, hdlr, err := newSupervisorHandler()
if err != nil {
log.Fatal(err)
}
auth := cfg.Server.HttpAuth
if auth.Enabled {
hdlr = httpauth.SimpleBasicAuth(auth.User, auth.Password)(hdlr)
}
http.Handle("/", hdlr)
addr := cfg.Server.Addr
if c.Bool("foreground") {
suv.AutoStartPrograms()
log.Printf("server listen on %v", addr)
log.Fatal(http.ListenAndServe(addr, nil))
} else {
if checkServerStatus() == nil {
fmt.Println("server is already running")
return nil
}
logPath := filepath.Join(defaultConfigDir, "gosuv.log")
logFd, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("create file %s failed: %v", logPath, err)
}
cmd := exec.Command(os.Args[0], "start-server", "-f")
cmd.Stdout = logFd
cmd.Stderr = logFd
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
select {
case err = <-GoFunc(cmd.Wait):
log.Fatalf("server started failed, %v", err)
case <-time.After(200 * time.Millisecond):
showAddr := addr
if strings.HasPrefix(addr, ":") {
showAddr = "0.0.0.0" + addr
}
fmt.Printf("server started, listening on %s\n", showAddr)
}
}
return nil
}
示例12: handleWrite
func handleWrite(ctx context.Context, c *client.Client) error {
n, err := c.Write(ctx, writeName, writeOffset, []byte(writeData), writeAppend)
if err != nil {
log.Fatalf("Write err (%v)", err)
}
log.Infof("%d bytes written to %s at offset %d", n, writeName, writeOffset)
return nil
}
示例13: handleRename
func handleRename(ctx context.Context, c *client.Client) error {
err := c.Rename(ctx, renameOld, renameNew)
if err != nil {
log.Fatalf("Rename err (%v)", err)
}
log.Infof("rename %s into %s", renameOld, renameNew)
return nil
}
示例14: handleMkdir
func handleMkdir(ctx context.Context, c *client.Client) error {
err := c.Mkdir(ctx, mkdirName, mkdirAll)
if err != nil {
log.Fatalf("Mkdir err (%v)", err)
}
fmt.Printf("mkdir %s succeeded\n", mkdirName)
return nil
}
示例15: handleRead
func handleRead(ctx context.Context, c *client.Client) error {
_, data, _, err := c.Read(ctx, readName, readOffset, readLen, readExpChecksum)
if err != nil {
log.Fatalf("Read err (%v)", err)
}
log.Info(string(data))
return nil
}