func init() { //获取当天时间 now := time.Now().Format("2006-01-02") file, err := os.OpenFile("/Users/mac/mygo/src/blog/log/"+now+".log", os.O_RDWR|os.O_APPEND, 0644) if err != nil { fd, err := os.Create("/Users/mac/mygo/src/blog/log/" + now + ".log") if err != nil { beego.Critical("openfile beepkg.log:", err) return } lg := log.New(fd, "", log.Ldate|log.Ltime) beego.SetLogger(lg) } lg := log.New(file, "", log.Ldate|log.Ltime) beego.SetLogger(lg) }
func init() { /* 로그기록 */ //NewLogger(10000) beego.SetLogger("file", `{"filename":"server.log"}`) /* 데이타베이스 드라이브 설정 */ orm.RegisterDriver("mysql", orm.DR_MySQL) orm.RegisterDataBase("default", "mysql", "root:Kim616294.@/cluber?charset=utf8&loc=Asia%2FSeoul") /* 데이타베이스 테이블 등록 */ orm.RegisterModel(new(models.User)) orm.RegisterModel(new(models.Log)) orm.RegisterModel(new(models.Contents)) // 사용 데이타베이스 name := "default" // 서버 시작시 테이블 재생성 force := false // SQL 로그 확인 verbose := true // 데이타베이스를 동기화 하고 에러 발생시 err 에 에러내용 입력 err := orm.RunSyncdb(name, force, verbose) if err != nil { fmt.Println(err) } }
func init() { // Try to have highest performance. runtime.GOMAXPROCS(runtime.NumCPU()) // Set application log level. beego.SetLevel(beego.LevelTrace) // Initialize log file. os.Mkdir("./log", os.ModePerm) // Compute log file name as format '<year>-<month>-<day>.txt', eg.'2013-5-6.txt'. logName := fmt.Sprintf("./log/%d-%d-%d.txt", time.Now().Year(), time.Now().Month(), time.Now().Day()) // Open or create log file. var fl *os.File var err error if utils.IsExist(logName) { fl, err = os.OpenFile(logName, os.O_RDWR|os.O_APPEND, 0644) } else { fl, err = os.Create(logName) } if err != nil { beego.Trace("Failed to init log file ->", err) return } beego.Info("Go Walker", VERSION) beego.SetLogger(log.New(fl, "", log.Ldate|log.Ltime)) }
func init() { beego.Router("/", &controllers.RootController{}) beego.Router("/login/?:dest", &controllers.LoginController{}) beego.Router("/logout/?:dest", &controllers.LogoutController{}) beego.Router("/signup/?:dest", &controllers.SignupController{}) beego.Router("/live-editor/", &controllers.LiveEditorController{}) beego.Router("/graphics-animation/", &controllers.GraphicsController{}) beego.Router("/external/:file", &controllers.LiveEditorController{}) beego.SetStaticPath("/build", "bootstrap/live-editor/build") var FilterUser = func(ctx *context.Context) { _, ok := ctx.Input.Session("uid").(int) if !ok { ctx.Redirect(302, "/login") } } beego.InsertFilter("/user/:id([0-9]+)", beego.BeforeRouter, FilterUser) beego.ErrorController(&controllers.ErrorController{}) beego.SetLogger("file", `{"filename":"log/spielplatz.log"}`) loadLanguages() }
func main() { initDb() beego.InsertFilter("/*", beego.BeforeRouter, FilterUser) wbconf.LoadCategory() beego.SetLogger("file", `{"filename":"logs/running.log", "level":6 }`) beego.Run() }
func main() { beego.SetLevel(beego.LevelInformational) beego.SetLogFuncCall(true) beego.SetLogger("file", `{"filename":"logs/test.log"}`) orm.Debug = true orm.RunSyncdb("default", false, true) beego.Run() }
func main() { beego.SetLogger("file", `{"filename":"logs/output.log"}`) beego.SetLogFuncCall(true) controllers.DIYFunc() beego.ErrorController(&controllers.ErrorController{}) beego.Run() }
func Initialize(c conf.Logger) (err error) { switch c.Dist { case "file": if c.File.Minutes <= 0 { return } loggerErrChan := make(chan error) now := time.Now() m := now.Minute() i := (c.File.Minutes-(m-(m/c.File.Minutes*c.File.Minutes)))*60 - now.Second() go func(i int) { //Pre declaration need this for excluding redeclare any time variables in unlimited loop var dir, s string var err error var now time.Time for { now = time.Now() dir = c.File.Folder + fmt.Sprintf("%02d_%02d_%02d", now.Day(), now.Month(), now.Year()) err = os.MkdirAll(dir, os.ModePerm) if err == nil { s = dir + "/" + fmt.Sprintf("%02d_%02d", now.Hour(), now.Minute()/c.File.Minutes*c.File.Minutes) if c.File.Ext != "" { s += "." + c.File.Ext } err = beego.SetLogger("file", `{"filename":"`+s+`"}`) } if err != nil { loggerErrChan <- err } time.Sleep(time.Millisecond * 1000 * time.Duration(i)) i = c.File.Minutes * 60 } }(i) go func() { for { beego.Error(<-loggerErrChan) } }() } return }
func main() { //beego.EnableAdmin = true //beego.AdminHttpPort = 3001 beego.SetLogger("console", "") beego.Router("/", &MainController{}) if beego.AppConfig.String("imagepath") != imagePath { imagePath = beego.AppConfig.String("imagepath") } beego.Run() }
func main() { beego.SetLogger("file", `{"filename":"logs/beego_bootstrap_api.log"}`) orm.RunCommand() if beego.BConfig.RunMode == "dev" { orm.Debug = true file, _ := os.OpenFile("logs/orm.log", os.O_APPEND|os.O_WRONLY, 0600) orm.DebugLog = orm.NewLog(file) } beego.Run() }
func main() { orm.Debug = true //第二个参数表示数据表是不是每次启动的时候删除再重建,第三个参数是打印相关信息 orm.RunSyncdb("default", false, true) fmt.Println("这是一个测试代码") beego.SetLogger("file", `{"filename":"logs/test.log"}`) beego.Run() }
func main() { //initCache() orm.Debug, _ = beego.AppConfig.Bool("orm_debug") //logFile := beego.AppConfig.String("log_file") beego.SetLogger("file", `{"filename":"logs/o2oapi.log"}`) beego.SetLogFuncCall(true) beego.Run() }
func init() { showNumberLine, _ := beego.AppConfig.Bool("logger.numberLine") levelString := beego.AppConfig.String("logger.level") logModels := beego.AppConfig.Strings("logger.logger") for _, logModel := range logModels { if logModel == "console" { beego.SetLogger("console", "") } if logModel == "file" { filename := beego.AppConfig.String("logger.filename") config := fmt.Sprintf(`{"filename":"%s","maxdays":30}`, filename) beego.SetLogger("file", config) } } if showNumberLine { beego.SetLogFuncCall(showNumberLine) } level, _ := Levelify(levelString) beego.SetLevel(level) }
func InitLog() { if beego.BConfig.RunMode == "dev" { beego.Info("initiating log") } logconf, err := gofile.IoUtilReadFile(filepath.Join(beego.AppPath, "conf", "log.json")) if err != nil { panic(err) } else { beego.SetLogger("file", string(logconf)) } }
func main() { if beego.RunMode != "dev" { beego.BeeLogger.SetLevel(logs.LevelWarning) beego.BeeLogger.DelLogger("console") beego.SetLogger("file", `{"filename":"logs/app.log"}`) } else { beego.BeeLogger.SetLevel(logs.LevelDebug) } beego.Run() }
func init() { ////// 初始化日志 beego.SetLogger("file", `{"filename":"go_dg.log"}`) iniconf, err := config.NewConfig("ini", "config.conf") if err != nil { beego.Error("init config error", err) beego.BeeLogger.Flush() panic("init failed") } Config_Data_URL = iniconf.String("data_url") Config_PRS_URL = iniconf.String("prs_url") }
func main() { beego.SessionOn = true beego.ErrorController(&controllers.ErrorController{}) beego.AddFuncMap("i18n", i18n.Tr) beego.EnableAdmin = true // Port 8088 beego.SetLogger("file", `{"filename":"logs/juna.log"}`) beego.SetLevel(beego.LevelInformational) beego.SetLogFuncCall(true) beego.AddFuncMap("news", news) beego.Run() }
func main() { models.InitDb() beego.SessionOn = true beego.SetLogger("file", `{"filename":"`+common.Webconfig.LogFile+`"}`) beego.SetLevel(beego.LevelInformational) beego.SetLogFuncCall(true) beego.Info("begin setting router") beego.Router("/", &routers.HomeRouter{}) beego.Router(`/page/:page([\d]+)`, &routers.HomeRouter{}) beego.Router(`/article/:article([\w-]+)`, &routers.ArticleRouter{}) beego.Router(`/tag/:tag([\S]+)/:page([\d]+)`, &routers.TagRouter{}) beego.Router(`/tag/:tag([\S]+)`, &routers.TagRouter{}) beego.Router(`/node/:node([\S]+)/:page([\d]+)`, &routers.NodeRouter{}) beego.Router(`/node/:node([\S]+)`, &routers.NodeRouter{}) beego.Router(`/category/:category([\S]+)/:page([\d]+)`, &routers.CategoryRouter{}) beego.Router(`/category/:category([\S]+)`, &routers.CategoryRouter{}) beego.Router("/subscribe", &routers.SubscribeRouter{}) beego.Router(`/subscribe/:uid([\S]+)`, &routers.SubscribeRouter{}) beego.Router(`/desubscribe/:uid([\S]+)`, &routers.SubscribeRouter{}) beego.Router("/root", &root.RootMainRouter{}) beego.Router("/root/category", &root.RootCategoryRouter{}) beego.Router("/root/node", &root.RootNodeRouter{}) beego.Router("/root/tag", &root.RootTagRouter{}) beego.Router(`/root/article`, &root.RootArticleRouter{}) //beego.Router(`/root/article/:opt([a-z]+)`, &root.RootArticleRouter{}) beego.Router(`/root/article/:page([\d]+)`, &root.RootArticleRouter{}) beego.Router("/root/upload", &root.RootUploadRouter{}) beego.Router("/root/login", &root.LoginRouter{}) beego.Router("/root/loginout", &root.LoginOutRouter{}) beego.Router(`/prompt/:code([\w]+)`, &routers.PromptRouter{}) beego.Info("starting server") beego.Run() }
func init() { GlobalSessions, _ = session.NewManager("memory", `{ "cookieName":"lte_securityid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": true, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`) go GlobalSessions.GC() beego.SetLogger("file", `{"filename":"logs/server.log"}`) beego.SetLevel(beego.LevelDebug) }
// We have to call a initialize function manully // because we use `bee bale` to pack static resources // and we cannot make sure that which init() execute first. func initialize() { setting.LoadConfig() //set logger if setting.IsProMode { beego.SetLogger("file", `{"filename":"logs/prod.log"}`) beego.SetLevel(beego.LevelInformational) beego.BeeLogger.DelLogger("console") } else { beego.SetLogger("file", `{"filename":"logs/dev.log"}`) beego.SetLevel(beego.LevelDebug) beego.BeeLogger.SetLogger("console", "") } beego.SetLogFuncCall(true) setting.SocialAuth = social.NewSocial("/login/", auth.SocialAuther) setting.SocialAuth.ConnectSuccessURL = "/settings/profile" setting.SocialAuth.ConnectFailedURL = "/settings/profile" setting.SocialAuth.ConnectRegisterURL = "/register/connect" setting.SocialAuth.LoginURL = "/login" //Qiniu ACCESS_KEY = setting.QiniuAccessKey SECRET_KEY = setting.QiniuSecurityKey }
func init() { //ceshi //设置log格式 beego.SetLogger("file", `{"filename":"logs/server.log"}`) beego.SetLevel(beego.LevelDebug) //设置session /*kkk beego.SessionOn = true beego.SessionProvider = "redis" beego.SessionSavePath = "192.168.15.43:6379" beego.SessionName = "LMSsessionID" beego.SessionGCMaxLifetime = 60 beego.SessionCookieLifeTime = 60 */ }
func main() { beego.SetLogger("file", fmt.Sprintf("{\"filename\":\"%s/%s.log\"}", beego.AppConfig.String("log::FilePath"), beego.AppConfig.String("log::FileName"))) app := cli.NewApp() app.Name = beego.AppConfig.String("appname") app.Usage = beego.AppConfig.String("usage") app.Version = beego.AppConfig.String("version") app.Author = "Meaglit Ma" app.Email = "*****@*****.**" app.Commands = []cli.Command{ cmd.CmdWeb, } app.Flags = append(app.Flags, []cli.Flag{}...) app.Run(os.Args) }
func init() { //设置log格式 beego.SetLogger("file", `{"filename":"logs/server.log"}`) beego.SetLevel(beego.LevelDebug) //设置下载脚本目录 beego.SetStaticPath("/script_download", "script_download") //设置session /* beego.SessionOn = true beego.SessionProvider = "redis" beego.SessionSavePath = "192.168.15.43:6379" beego.SessionName = "LMSsessionID" beego.SessionGCMaxLifetime = 60 beego.SessionCookieLifeTime = 60 */ }
func main() { //setUserId() graceful, _ := beego.AppConfig.Bool("graceful") if !graceful { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) go handleSignals(sigs) } beego.SetLogger("file", `{"filename":"logs/test.log"}`) mode := beego.AppConfig.String("runmode") if mode == "prod" { beego.SetLevel(beego.LevelInformational) } beego.Run() }
func main() { beego.AddFuncMap("VaildError", vaildError) beego.SetStaticPath("amaze", "static/amaze") beego.SetStaticPath("hp", "static/hp") beego.SetStaticPath("term", "static/term") beego.SetStaticPath("static", "static") beego.ErrorController(&controllers.ErrorController{}) router() loggerConfig := `{ "filename":"log/beego.log", "maxlines" : 1000, "maxsize" : 10240, "rotate": true, "daily":true, "maxdays":10 }` beego.SetLogger("file", loggerConfig) beego.Run() }
func main() { m.Connect() beego.ViewsPath = "views" beego.TemplateLeft = "<<<" beego.TemplateRight = ">>>" beego.AddTemplateExt("html") beego.SetStaticPath("/public", "public") beego.SetLogger("file", `{"filename":"logs/finprocess.log"}`) beego.SetLogFuncCall(true) logLevel, _ := beego.AppConfig.Int("log_level") beego.SetLevel(logLevel) //minutes for duration duration, _ := beego.AppConfig.Int("task_duration") go tasks.DailyTaskInit(duration) //启动task beego.Run() }
func main() { beego.Info("ModuleAB server", version.Version, "starting...") logfile := beego.AppConfig.String("logFile") if logfile == "" { logfile = "logs/moduleab_server.log" } err := beego.SetLogger("file", fmt.Sprintf(`{"filename":"%s"}`, logfile)) if err != nil { panic(err) } beego.SetLevel(beego.LevelInformational) beego.Info("Hello!") // 别用root运行我! if os.Getuid() == 0 { beego.Alert("Hey! You're running this server with user root!") panic("Don't run me with root!") } switch beego.BConfig.RunMode { case "initdb": beego.Info("Got runmode: Initialize database") err = orm.RunSyncdb("default", true, true) orm.Debug = true policies.InitDb() beego.Info("Database is ready") os.Exit(0) case "dev": beego.Info("Got runmode: Development") beego.SetLevel(beego.LevelDebug) beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.Debug("Now import database") orm.Debug = true err = orm.RunSyncdb("default", false, true) case "deb": beego.Info("Got runmode: Debug") beego.SetLevel(beego.LevelDebug) beego.Debug("Now import database") orm.Debug = true err = orm.RunSyncdb("default", false, true) default: beego.BeeLogger.DelLogger("console") err = orm.RunSyncdb("default", false, false) } if err != nil { beego.Alert("Database error:", err, ". go exit.") os.Exit(1) } beego.Debug("Current PID:", os.Getpid()) ioutil.WriteFile( beego.AppConfig.String("pidFile"), []byte(fmt.Sprint(os.Getpid())), 0600, ) beego.Info("Run check oas job...") go policies.CheckOasJob() beego.Info("All is ready, go running...") beego.BConfig.WebConfig.Session.SessionOn = true beego.BConfig.WebConfig.Session.SessionName = "Session_MobuleAB" beego.Run() defer func() { x := recover() if x != nil { beego.Error("Got fatal error:", x) stack := make([]byte, 0) runtime.Stack(stack, true) beego.Error("Stack trace:\n", string(stack)) os.Exit(1) } }() }
func main() { beego.SetLogger("file", `{"filename":"logs/server.log"}`) beego.BeeLogger.Async() beego.Run() }
func init() { beego.SetLogger("file", `{"filename":"log"}`) //beego.SetLevel(beego.LevelInformational) }
func main() { beego.SetLogger("file", `{"filename":"./log/inote.log"}`) beego.ErrorController(&controllers.ErrorController{}) beego.Run() }