Ejemplo n.º 1
0
func main() {
	cfg := kolonsecfg.NewCfg()
	cfg.ParseFile(*cfgPath)
	cfgNode := cfg.Child(*env)
	logger := logs.NewLogger(10000)
	// 创建配置日志文件目录
	os.MkdirAll(cfgNode.Child("log.logdir").GetString(), 0777)
	filename := path.Join(cfgNode.Child("log.logdir").GetString(),
		cfgNode.Child("log.filename").GetString())
	logCfg := map[string]interface{}{
		"filename": filename,
		"maxlines": cfgNode.Child("log.maxlines").GetInt(),
		"maxsize":  cfgNode.Child("log.maxsize").GetInt(),
		"daily":    cfgNode.Child("log.daily").GetBool(),
		"maxdays":  cfgNode.Child("log.maxdays").GetInt(),
		"rotate":   cfgNode.Child("log.rotate").GetBool(),
	}
	buff, _ := json.Marshal(logCfg)
	err := logger.SetLogger("file", string(buff))
	if err != nil {
		panic(err.Error())
	}
	err = logger.SetLogger("console", "")
	if err != nil {
		panic(err.Error())
	}
	logger.Info("当前环境:%v 加载配置:\n%v", *env, cfgNode.Dump(""))
	ts := TCPServer.NewTCPServer(cfgNode.Child("serveraddr").GetString())
	ts.Register("logger", logger)
	ts.Register("newConnCB", function.Bind(ClientConnect, function.P_1))
	ts.Register("recvCB", function.Bind(ClientDataRecv, function.P_1, function.P_2, function.P_3))
	ts.Server()
}
Ejemplo n.º 2
0
func DefaultLogs() *logs.BeeLogger {
	ret := logs.NewLogger(10000)
	err := ret.SetLogger("console", "")
	if err != nil {
		panic(err)
	}
	ret.EnableFuncCallDepth(true)
	ret.SetLogFuncCallDepth(3)
	return ret
}
Ejemplo n.º 3
0
func NewTCPServer(addr string) *TCPServer {
	logger := logs.NewLogger(10000)
	err := logger.SetLogger("console", "")
	if err != nil {
		panic(err.Error())
	}
	logger.EnableFuncCallDepth(true)
	logger.SetLogFuncCallDepth(3)

	return &TCPServer{
		Addr:   addr,
		logger: logger,
		exit:   make(chan bool, 1),
	}
}