示例#1
0
文件: log.go 项目: y8y/OWL-v3
func init_log(cfg *Config) error {
	//数据接收日志
	dlog = logs.NewLogger(100)
	dlog.EnableFuncCallDepth(true)
	dlog.SetLevel(cfg.LOG_LEVEL)
	if err := dlog.SetLogger("file", fmt.Sprintf(`{"filename":"%s/data.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}
	//网络设备日志
	nlog = logs.NewLogger(100)
	nlog.EnableFuncCallDepth(true)
	nlog.SetLevel(cfg.LOG_LEVEL)
	if err := nlog.SetLogger("file", fmt.Sprintf(`{"filename":"%s/netdevice.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}

	slog = logs.NewLogger(100)
	slog.EnableFuncCallDepth(true)
	slog.SetLevel(cfg.LOG_LEVEL)
	if err := slog.SetLogger("file", fmt.Sprintf(`{"filename":"%s/server.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}
	return nil
	//客户端日志
	//
}
示例#2
0
func init() {
	normal_log = logs.NewLogger(10000)
	normal_log.EnableFuncCallDepth(true)
	access_log_file := beego.AppConfig.String("access_log")
	normal_log.SetLogger("file", `{"filename":"`+access_log_file+`"}`)
	error_log = logs.NewLogger(10000)
	error_log.EnableFuncCallDepth(true)
	error_log_file := beego.AppConfig.String("error_log")
	error_log.SetLogger("file", `{"filename":"`+error_log_file+`"}`)
}
示例#3
0
func main() {
	log := logs.NewLogger(10000)
	log.SetLogger("file", `{"filename":"/tmp/wallpaper.log"}`)
	log.Info("Start===================")
	v := Bing{}
	req := httplib.Get("http://www.bing.com/HPImageArchive.aspx?format=json&idx=0&n=1")
	err := req.ToXml(&v)

	if len(v.Images) > 0 && err == nil {
		pic := httplib.Get(bingURL + v.Images[0].Url)
		fmt.Println(file_path)
		err = pic.ToFile(file_path)
		if err != nil {
			log.Error("save file error %v.............", err)
		} else {
			log.Info("download wallpeper success..........")
			cmd := exec.Command("gsettings", "set", "org.gnome.desktop.background", "picture-uri", fmt.Sprintf("file:%s", file_path))
			err := cmd.Start()
			log.Info("Waiting for command to finish.........")
			err = cmd.Wait()
			log.Info("Command finished with error: %v", err)
			if err != nil {
				log.Error("%v............", err)
			}
			log.Info("set wallpeper success..........")
		}
	}
	log.Info("End===================")
}
示例#4
0
文件: index.go 项目: cnhans/kingdoms
func init() {
	//根据随机时间种子实例化随机数
	newRand = rand.New(rand.NewSource(time.Now().UnixNano()))
	//如果没有日志目录则创建日志目录
	_, err := os.Open("log")
	if err != nil && os.IsNotExist(err) {
		os.Mkdir("log", 0777)
	}
	//初始化日志
	log = logs.NewLogger(10000)
	log.SetLogger("file", `{"filename":"log/kingdoms.log"}`)
	//初始化又拍云
	/// 初始化空间
	ku = upyun.NewUpYun("kingdoms", beego.AppConfig.String("UpyunAccount"), beego.AppConfig.String("UpyunPassword"))
	ku.SetApiDomain("v0.api.upyun.com")
	//初始化技能
	allskill = &logic.AllSkill{}
	//初始化所有图片json值
	updateImage()
	//初始化游戏数据
	cardRanks = "100,500,2000,10000"
	chuanqi = []int{16, 132, 181, 230, 278, 308, 501, 539, 566}
	shenjiang = []int{17, 18, 24, 26, 57, 84, 91, 98, 180, 190, 192, 196, 233, 294, 395, 575}
	hujiang = []int{14, 20, 25, 27, 29, 31, 32, 33, 129, 130, 131, 183, 191, 215, 220, 225, 229, 237, 283, 284, 285, 288, 293, 296, 297, 352, 383, 450, 451, 479, 495, 530, 546, 574, 576, 577}
	putong = []int{20}
	xiaobing1 = []int{1001, 1002, 1003, 1004, 1005, 1006}
	xiaobing2 = []int{1007, 1008, 1009, 1010, 1011, 1012}
	xiaobing3 = []int{1013, 1014, 1015, 1016, 1017, 1018}
	RliveCost = 10
	//赋值所有卡牌
	SetAllCards()
}
示例#5
0
func init() {
	log = logs.NewLogger(10000)
	log.SetLogger("file", `{
		"filename": "storage/logs/access.log",
		"maxdays": 365
	}`)
}
示例#6
0
文件: logger.go 项目: nevernet/logger
func init() {
	log = logs.NewLogger(10000)
	log.SetLogger("console", `{"level": 10}`)
	log.SetLevel(logs.LevelDebug)
	log.EnableFuncCallDepth(true)
	log.SetLogFuncCallDepth(3)
	log.Async()
}
示例#7
0
文件: log.go 项目: wuxu92/snp
func GetLogger() *logs.BeeLogger {
	if logger == nil {
		logger = logs.NewLogger(1000)
		logger.SetLevel(logs.LevelInfo)
		//		today := time.Now().YearDay()
		logger.SetLogger("file", `{"filename":"logs/snp.log","daily":true}`)
	}
	return logger
}
示例#8
0
func WriteErrorLog(format string, v ...interface{}) {
	log := logs.NewLogger(10000)
	fname := getLogFileName()
	sfile := fmt.Sprintf("{\"filename\":\"%s\"}", fname)
	log.SetLogger("file", sfile)
	//log.SetLogger("file", `{"filename":"solar.log"}`)

	log.Error(format, v...)
}
示例#9
0
文件: log.go 项目: wuxu92/snp
func GetConsole() *logs.BeeLogger {
	if console == nil {
		fmt.Println("new console logger")
		console = logs.NewLogger(1000)
		console.SetLevel(logs.LevelInfo)
		console.SetLogger("console", `{}`)
	}
	return console
}
示例#10
0
func InitLog(runmode, path string) {
	Log = logs.NewLogger(10000)

	if runmode == "dev" {
		Log.SetLogger("console", "")
	}

	Log.SetLogger("file", fmt.Sprintf("{\"filename\":\"%s\"}", path))

}
示例#11
0
文件: log.go 项目: y8y/OWL-v3
func init_log(cfg *Config) error {
	//数据接收日志
	log = logs.NewLogger(100)
	log.EnableFuncCallDepth(true)
	log.SetLevel(cfg.LOG_LEVEL)
	if err := log.SetLogger("file", fmt.Sprintf(`{"filename":"%s/proxy.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}
	dlog = logs.NewLogger(100)
	dlog.EnableFuncCallDepth(true)
	dlog.SetLevel(cfg.LOG_LEVEL)
	if err := dlog.SetLogger("file", fmt.Sprintf(`{"filename":"%s/data.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}

	return nil
}
示例#12
0
文件: mylog.go 项目: slygo/slygoblog
func (this *BeeLooger) LogEngine() {
	mylog := GetInstanceForMyLog()
	//初始化日志
	mylog = logs.NewLogger(10000)
	//设置日志引擎
	mylog.SetLogger("file", `"filename":"slygoblog.log","maxlines":11,"maxdays":1`)

	mylog.SetLogFuncCallDepth(2)
	mylog.EnableFuncCallDepth(false)
}
示例#13
0
文件: logger.go 项目: rechen/dockyard
func init() {
	Log = logs.NewLogger(10000)

	if setting.RunMode == "dev" {
		Log.SetLogger("console", "")
	}

	Log.SetLogger("file", fmt.Sprintf("{\"filename\":\"%s\"}", setting.LogPath))

}
示例#14
0
文件: log.go 项目: y8y/OWL-v3
func init_log() error {
	log = logs.NewLogger(100)
	log.EnableFuncCallDepth(true)
	log.SetLevel(cfg.LOG_LEVEL)
	if err := log.SetLogger("file", fmt.Sprintf(`{"filename":"%s/client.log","rotate":true,"maxdays":%d}`,
		cfg.LOG_DIR, cfg.LOG_EXPIRE_DAYS)); err != nil {
		return err
	}
	return nil
}
示例#15
0
func LogItemDelete(item interface{}, deleter string) bool {
	log := logs.NewLogger(10000)
	log.SetLogger("file", `{"filename":"db/deletedItems.log"}`)
	if b, err := json.Marshal(item); err == nil {
		fmt.Println(b)
		beego.Warn("deleter: ", deleter, " item: ", string(b))
		log.Info("deleter: ", deleter, " item: ", string(b))
		return true
	}
	return false
}
示例#16
0
文件: main.go 项目: zkbcoder/gosrc
func main() {
	InitXml(&g_dbs) // 加载xml配置
	// log初始化
	beelog = logs.NewLogger(10000)
	beelog.SetLogger("file", `{"filename":"run.log"}`)
	beelog = beelog.Async()
	// errlog初始化
	errlog = logs.NewLogger(10000)
	errlog.SetLogger("file", `{"filename":"err.log"}`)
	errlog = errlog.Async()

	AlterMysqlDB("InnoDB", true)
	count := len(g_dbs.DBConfig)
	for i := 1; i < count; i++ {
		StartMerge(g_dbs.DBConfig[0], g_dbs.DBConfig[i])
	}
	AlterMysqlDB("MyISAM", false)

	return
}
示例#17
0
func init() {
	//如果没有日志目录则创建日志目录
	_, err := os.Open("log")
	if err != nil && os.IsNotExist(err) {
		os.Mkdir("log", 0777)
	}
	//初始化日志
	SocketLog = logs.NewLogger(10000)
	SocketLog.SetLogger("file", `{"filename":"log/socket.log"}`)
	//初始化客户端
	Clients = make(map[string]*websocket.Conn, 1000)
}
示例#18
0
文件: api.go 项目: treejames/Dream
func init() {
	//如果没有日志目录则创建日志目录
	_, err := os.Open("log")
	if err != nil && os.IsNotExist(err) {
		os.Mkdir("log", 0777)
	}
	//初始化日志
	ApiLog = logs.NewLogger(10000)
	ApiLog.SetLogger("file", `{"filename":"log/api.log"}`)
	//初始化邮箱
	mail = utils.NewEMail(`{"username":"******","password":"******"EmailPassword") + `","host":"smtp.isletsacg.com","port":25}`)
}
示例#19
0
func (this *TestController) Jia() {

	utility.ViewLogin(this.Ctx)

	log := logs.NewLogger(10000)
	log.SetLogger("console", "")

	//log.Info(strconv.Itoa(int(datatype.Golang)))

	log.Info(this.Ctx.Input.Uri())
	this.TplNames = "test/index.html"
}
示例#20
0
文件: log.go 项目: TalkingData/OWL-v3
func InitLog() error {
	lg = logs.NewLogger(100)
	lg.EnableFuncCallDepth(true)
	lg.SetLogger("console", "")
	param := fmt.Sprintf(`{"filename":"%s","rotate":true,"maxdays":%d}`,
		GlobalConfig.LOG_FILE, GlobalConfig.LOG_EXPIRE_DAYS)
	if err := lg.SetLogger("file", param); err != nil {
		return err
	}
	lg.SetLevel(GlobalConfig.LOG_LEVEL)
	return nil
}
示例#21
0
文件: jwt.go 项目: ngaut/beego
// CreateToken return the token
func CreateToken() map[string]string {
	log := logs.NewLogger(10000)
	log.SetLogger("console", "")

	token := goJwt.New(goJwt.GetSigningMethod("RS256")) // Create a Token that will be signed with RSA 256.
	token.Claims["ID"] = "This is my super fake ID"
	token.Claims["exp"] = time.Now().Unix() + 36000
	// The claims object allows you to store information in the actual token.
	tokenString, _ := token.SignedString(RSAKeys.PrivateKey)
	// tokenString Contains the actual token you should share with your client.
	return map[string]string{"token": tokenString}
}
示例#22
0
文件: log.go 项目: fishedee/reproxy
// 初始化日志模块
func newLogger(config LogConfig, isDaily bool) (*logs.BeeLogger, error) {
	var logger *logs.BeeLogger

	var configInner logConfigInner
	if config.Filename == "" {
		return logger, errors.New("文件名不能为空哈")
	}
	configInner.Filename = config.Filename

	if config.Maxlines == 0 {
		config.Maxlines = 1000000
	}
	configInner.Maxlines = config.Maxlines

	configInner.Daily = isDaily

	if config.Maxdays == 0 {
		config.Maxdays = 7
	}
	configInner.Maxdays = config.Maxdays

	logLevel := map[string]int{
		"error": logs.LevelError,
		"warn":  logs.LevelWarning,
		"info":  logs.LevelInformational,
	}
	var logLevelInt int
	if config.Level == "" {
		logLevelInt = logs.LevelInformational
	} else {
		var ok bool
		logLevelInt, ok = logLevel[config.Level]
		if ok == false {
			return logger, errors.New("日志等级设置不正确")
		}
	}
	configInner.Level = logLevelInt
	configInner.Rotate = true

	// 普通日志
	logger = logs.NewLogger(10000)
	logConfigString, err := json.Marshal(&configInner)
	if err != nil {
		return logger, err
	}

	err = logger.SetLogger("file", string(logConfigString))
	if err != nil {
		return logger, err
	}

	return logger, nil
}
示例#23
0
// set logfile, loglevel
func SetLog() error {
	logjsonconf := `{
		"filename":"log.log",
		"daily":true,
		"maxDays":15,
		"rotate":true,
		"perm":600
	}`

	// "maxsize":1e10,
	var logconfmap map[string]interface{}
	if err := json.Unmarshal([]byte(logjsonconf), &logconfmap); err != nil {
		return err
	}

	log = logs.NewLogger(10000)

	logfilename := conf.Get("global", "log")
	if len(logfilename) != 0 {
		logconfmap["filename"] = logfilename
	}

	fmt.Printf("log file is [%s]\n", logfilename)

	jsonconf, err := json.Marshal(logconfmap)
	if err != nil {
		fmt.Println("HHH", err)
		return err
	}

	log.SetLogger("file", string(jsonconf))

	loglevelstr := conf.Get("global", "loglevel")
	if len(loglevelstr) == 0 {
		loglevelstr = "8" // Debug
	}

	if loglevelstr > "3" {
		log.EnableFuncCallDepth(true)
	}

	loglevel, err := strconv.Atoi(loglevelstr)
	if err != nil {
		return fmt.Errorf("logLevel is invalid:", loglevelstr)
	}

	log.SetLevel(loglevel)

	log.Emergency("hahaproxy start!")

	return nil
}
示例#24
0
func InitLog() bool {
	logInst = logs.NewLogger(1000)
	if logInst == nil {
		panic("sdfdf")
		return false
	}

	logInst.SetLogger("console", "")
	logInst.EnableFuncCallDepth(true)
	logInst.SetLogFuncCallDepth(3)

	return true
}
示例#25
0
文件: logs.go 项目: RT7oney/tutorial
func main() {
	log := logs.NewLogger(10000)
	log.SetLogger("console", "")
	log.EnableFuncCallDepth(true) // 开启文件和行号显示
	log.Trace("trace %s %s", "param1", "param2")
	log.Debug("debug")
	log.Info("info")
	log.Warn("warning")
	log.Error("error")
	log.Critical("critical")

	time.Sleep(1 * 1e9) // why ?
}
示例#26
0
func InitLogger() {
	logPath := beego.AppConfig.String("server_log_path")
	Logger = logs.NewLogger(10000)
	Logger.EnableFuncCallDepth(true) // 输出调用的文件名和文件行号
	//filename 保存的文件名
	//maxlines 每个文件保存的最大行数,默认值 1000000
	//maxsize 每个文件保存的最大尺寸,默认值是 1 << 28, //256 MB
	//daily 是否按照每天 logrotate,默认是 true
	//maxdays 文件最多保存多少天,默认保存 7 天
	//rotate 是否开启 logrotate,默认是 true
	//level 日志保存的时候的级别,默认是 Trace 级别
	Logger.SetLogger("file", `{"filename":"`+logPath+"fserver.log"+`"}`)
}
示例#27
0
文件: client.go 项目: hinike/gowebQQ
func New(id, password string, timeout int, logchannellen int64) *Client {
	rd := rand.New(rand.NewSource(time.Now().UnixNano()))
	c := &Client{
		id:       id,
		password: password,
		clientid: strconv.Itoa(rd.Intn(90000000) + 10000000),
		client:   newClient(time.Duration(timeout)),
		msgid:    (rd.Int63n(9000) + 1000) * 10000,
	}
	c.BeeLogger = logs.NewLogger(logchannellen)
	lg = c.BeeLogger
	return c
}
示例#28
0
// NewBeeLogger 创建BeeLogger实例
func NewBeeLogger(conf *config.Config) *BeeLogger {
	filename := strings.TrimSpace(conf.Logger.LogFile)
	if strings.HasPrefix(filename, HomeDirFlag) {
		filename, _ = rel2Abs(filename)
	}

	var logConf struct {
		FileName string `json:"filename"`
		Level    uint   `json:"level"`
	}
	logConf.FileName = filename
	logConf.Level = selectLevel(conf.Logger.Level)

	if err := os.MkdirAll(path.Dir(filename), os.ModePerm); err != nil {
		fmt.Printf("MkdirAll err: %s\n", err)
	}

	fileLogger := logs.NewLogger(1000)
	fileLogger.EnableFuncCallDepth(true) // 输出文件名和行号
	fileLogger.SetLogFuncCallDepth(3)

	logData, _ := json.Marshal(logConf)

	if err := fileLogger.SetLogger("file", string(logData)); err != nil {
		fmt.Printf("SetLogger err: %s\n", err)
	}

	// 尝试重置日志文件权限为0666
	os.Chmod(filename, 0666) // 不处理error

	// console log
	consoleLogger := logs.NewLogger(1000)
	consoleLogger.SetLogger("console", "")
	consoleLogger.EnableFuncCallDepth(true)
	consoleLogger.SetLogFuncCallDepth(3)

	return &BeeLogger{fileLogger, consoleLogger}
}
示例#29
0
文件: log.go 项目: baocaixiong/simage
func newLogger(channellen int64, logPath string) *logs.BeeLogger {
	logger := logs.NewLogger(channellen)

	if *debug {
		logger.SetLogger("console", "")
	}

	if _, err := os.Stat(logPath); os.IsNotExist(err) {
		fmt.Printf("no such file or directory: %s", logPath)
		return nil
	}

	return logger
}
示例#30
0
文件: api.go 项目: treejames/woku_old
func init() {
	//如果没有日志目录则创建日志目录
	_, err := os.Open("log")
	if err != nil && os.IsNotExist(err) {
		os.Mkdir("log", 0777)
	}
	//初始化日志
	ApiLog = logs.NewLogger(10000)
	ApiLog.SetLogger("file", `{"filename":"log/api.log"}`)
	//初始化邮箱
	mail = utils.NewEMail(`{"username":"******"EmailAccount") + `","password":"******"EmailPassword") + `","host":"` + beego.AppConfig.String("EmailSmtp") + `","port":` + beego.AppConfig.String("EmailPort") + `}`)
	//初始化又拍云
	u = upyun.NewUpYun("wokugame", beego.AppConfig.String("UpyunAccount"), beego.AppConfig.String("UpyunPassword"))
	u.SetApiDomain("v0.api.upyun.com")
}