本文整理汇总了Golang中github.com/alecthomas/log4go.Close函数的典型用法代码示例。如果您正苦于以下问题:Golang Close函数的具体用法?Golang Close怎么用?Golang Close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Close函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var err error
// Parse cmd-line arguments
flag.Parse()
log.Info("web ver: \"%s\" start", ver.Version)
if err = InitConfig(); err != nil {
panic(err)
}
// Set max routine
runtime.GOMAXPROCS(Conf.MaxProc)
// init log
log.LoadConfiguration(Conf.Log)
defer log.Close()
// init zookeeper
zkConn, err := InitZK()
if err != nil {
if zkConn != nil {
zkConn.Close()
}
panic(err)
}
// start pprof http
perf.Init(Conf.PprofBind)
// start http listen.
StartHTTP()
// process init
if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
panic(err)
}
// init signals, block wait signals
signalCH := InitSignal()
HandleSignal(signalCH)
log.Info("web stop")
}
示例2: Must
func (c *Client) Must(result *Result, err *AppError) *Result {
if err != nil {
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
return result
}
示例3: MustGeneric
// MustGeneric is a convenience function used for testing.
func (c *Client) MustGeneric(result interface{}, err *AppError) interface{} {
if err != nil {
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
return result
}
示例4: Must
func Must(sc StoreChannel) interface{} {
r := <-sc
if r.Err != nil {
l4g.Close()
time.Sleep(time.Second)
panic(r.Err)
}
return r.Data
}
示例5: UpdateUserToTeamAdmin
func UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_ADMIN}
if tmr := <-Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
l4g.Error(tmr.Err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(tmr.Err)
}
}
示例6: LinkUserToTeam
func LinkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
err := JoinUserToTeam(team, user)
if err != nil {
l4g.Error(err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
}
示例7: configureLog
func configureLog(s *model.LogSettings) {
l4g.Close()
if s.EnableConsole {
level := l4g.DEBUG
if s.ConsoleLevel == "INFO" {
level = l4g.INFO
} else if s.ConsoleLevel == "WARN" {
level = l4g.WARNING
} else if s.ConsoleLevel == "ERROR" {
level = l4g.ERROR
}
lw := l4g.NewConsoleLogWriter()
lw.SetFormat("[%D %T] [%L] %M")
l4g.AddFilter("stdout", level, lw)
}
if s.EnableFile {
var fileFormat = s.FileFormat
if fileFormat == "" {
fileFormat = "[%D %T] [%L] %M"
}
level := l4g.DEBUG
if s.FileLevel == "INFO" {
level = l4g.INFO
} else if s.FileLevel == "WARN" {
level = l4g.WARNING
} else if s.FileLevel == "ERROR" {
level = l4g.ERROR
}
flw := l4g.NewFileLogWriter(GetLogFileLocation(s.FileLocation), false)
flw.SetFormat(fileFormat)
flw.SetRotate(true)
flw.SetRotateLines(LOG_ROTATE_SIZE)
l4g.AddFilter("file", level, flw)
}
}
示例8: CreateTeam
func (me *TestHelper) CreateTeam() *model.Team {
id := model.NewId()
team := &model.Team{
DisplayName: "dn_" + id,
Name: "name" + id,
Email: "success+" + id + "@simulator.amazonses.com",
Type: model.TEAM_OPEN,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if team, err = CreateTeam(team); err != nil {
l4g.Error(err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return team
}
示例9: CreatePost
func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
id := model.NewId()
post := &model.Post{
UserId: me.BasicUser.Id,
ChannelId: channel.Id,
Message: "message_" + id,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if post, err = CreatePost(post, channel.TeamId, false); err != nil {
l4g.Error(err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return post
}
示例10: CreateUser
func (me *TestHelper) CreateUser() *model.User {
id := model.NewId()
user := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if user, err = CreateUser(user); err != nil {
l4g.Error(err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return user
}
示例11: createChannel
func (me *TestHelper) createChannel(team *model.Team, channelType string) *model.Channel {
id := model.NewId()
channel := &model.Channel{
DisplayName: "dn_" + id,
Name: "name_" + id,
Type: channelType,
TeamId: team.Id,
CreatorId: me.BasicUser.Id,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = CreateChannel(channel, true); err != nil {
l4g.Error(err.Error())
l4g.Close()
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
示例12: flushLogAndExit
func flushLogAndExit(code int) {
l4g.Close()
time.Sleep(time.Second)
os.Exit(code)
}
示例13: main
func main() {
defer logger.Close()
flag.Parse()
cpus := runtime.NumCPU()
logger.Info("CPU核心数=%d,\t并发数=%d,\t单线程请求数=%d,\t每次请求间隔时间=%d,\t请求地址=%s", cpus, *coroutines, *reqnum, *interval, *url)
timeStart := time.Now().UnixNano()
runtime.GOMAXPROCS(cpus)
coroutinesNum := *coroutines
subCoroutinesNum := *reqnum
count := coroutinesNum * subCoroutinesNum
ch := make(chan service.IaxResponse, count)
defer close(ch)
for i := 0; i < coroutinesNum; i++ {
go func(index int) {
// Start Coroutines
for j := 0; j < subCoroutinesNum; j++ {
st := time.Now().UnixNano()
req := service.IaxRequest{Id: index, SubId: j, Descr: "haha", Url: *url}
res := Request(req)
end := time.Now().UnixNano()
useTimeNano := end - st
if *interval > 0 && useTimeNano < int64(*interval*1000*1000) {
sleepTime := int64(*interval*1000*1000) - useTimeNano
time.Sleep(time.Nanosecond * time.Duration(sleepTime))
}
end = time.Now().UnixNano()
useTime := float64(end-st) / 1000.00 / 1000.00
res.UseTime = float32(round(useTime, 2))
ch <- res
}
}(i)
}
resultList := make([]service.IaxResponse, count)
next := true
var index int = 0
for next {
select {
case result := <-ch:
resultList[index] = result
index += 1
if index == count {
next = false
}
}
}
timeEnd := time.Now().UnixNano()
useTime := timeEnd - timeStart
minUseTime := resultList[0] // 最小用时
maxUseTime := minUseTime // 最大用时
success := 0 //成功总数
successMinUseTime := minUseTime // 状态成功最小用时
successMaxUseTime := successMinUseTime // 状态成功最大用时
successResult := 0
noAdsCount := 0
for index, value := range resultList {
if value.StatusCode == 200 {
success += 1
if value.UseTime < successMinUseTime.UseTime {
successMinUseTime = value
}
if value.UseTime > successMaxUseTime.UseTime {
successMaxUseTime = value
}
var result models.Result
bodyText := value.Body
bodyText = strings.Replace(bodyText, "window.admaxADMAX_1.serve.callback(", "", -1)
bodyText = strings.Replace(bodyText, ")", "", -1)
bodyText = strings.Replace(bodyText, "\n", "", -1)
bodyText = strings.Replace(bodyText, "\t", "", -1)
err := json.Unmarshal([]byte(bodyText), &result)
if err != nil {
logger.Error("%+v", err)
}
value.Result = result
if result.Success {
successResult += 1
}
if len(result.Ads[0].Link) < 100 || strings.HasPrefix(result.Ads[0].Link, "http") {
noAdsCount += 1
logger.Debug(" index=%d use=%.2f-ms\t ----> %s, %s\n", index, value.UseTime, result.Ads[0].BidId, result.Ads[0].Link)
}
}
if value.UseTime < minUseTime.UseTime {
minUseTime = value
}
if value.UseTime > maxUseTime.UseTime {
maxUseTime = value
}
//logger.Info("%d,%+v", index, value)
//.........这里部分代码省略.........
示例14: main
func main() {
// parse cmd-line arguments
flag.Parse()
log.Info("comet ver: \"%s\" start", ver.Version)
// init config
if err := InitConfig(); err != nil {
panic(err)
}
// set max routine
runtime.GOMAXPROCS(Conf.MaxProc)
// init log
log.Info("comet log configuration")
log.LoadConfiguration(Conf.Log)
defer log.Close()
// start pprof
log.Info("comet init perf")
perf.Init(Conf.PprofBind)
// create channel
// if process exit, close channel
UserChannel = NewChannelList()
defer UserChannel.Close()
// start stats
log.Info("comet start stats")
StartStats()
// start rpc,应该不需要了吧?
log.Info("comet start rpc")
if err := InitControllerRpcClient(); err != nil {
panic(err)
}
defer thriftPool.Release()
// start comet
log.Info("comet start ")
if err := StartComet(); err != nil {
panic(err)
}
// configuration the kafka topic and kafka consumer to consum the notify messages.
log.Info("queue start")
if err := StartQueue(); err != nil {
panic(err)
}
// init zookeeper,用来监控instance的启动和服务down。同步instance的ip,queue,信息到配置中心。配置中心监控监控变动,同步信息到调度中心。
zkConn, err := InitZK()
if err != nil {
if zkConn != nil {
zkConn.Close()
}
panic(err)
}
// process init
// if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
// panic(err)
// }
// init signals, block wait signals
signalCH := InitSignal()
HandleSignal(signalCH)
// exit
log.Info("comet stop")
}