Beispiel #1
0
func main() {

	log.SetLevel(log.DEBUG)
	log.SetRollingDaily("./log", "test.log")
	log.Info("test")
	var t int = 4
	log.Info("t before:", t)
	t -= 1
	log.Info("t after:", t)
}
Beispiel #2
0
func main() {

	log.SetLevel(log.DEBUG)
	log.SetRollingDaily("./", "tcp.log")

	listen, err := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(ip), port, ""})
	if err != nil {
		fmt.Println("监听端口失败:", err.Error())
		return
	}
	log.Info("等待客户端连接,port:", port)
	Server(listen)
}
Beispiel #3
0
func Server(listen *net.TCPListener) {
	for {
		conn, err := listen.AcceptTCP()
		if err != nil {
			log.Error("接受客户端连接异常:", err.Error())
			continue
		}
		fmt.Println("客户端连接来自:", conn.RemoteAddr().String())
		defer conn.Close()
		go func() {
			data := make([]byte, 128)
			for {
				i, err := conn.Read(data)
				if err != nil {
					fmt.Println("读取客户端数据错误:", err.Error())
					break
				}
				log.Info("客户端发来数据:", string(data[0:i]))
				conn.Write([]byte{'S', 'a', 'n', 'd', 'L', 'a', 'b'})
			}
		}()
	}
}
Beispiel #4
0
func main() {
	log.Info("log server start...")

	log.Info("log server start over.")
}