gf/g/net/ghttp/ghttp_server_config_logger.go

72 lines
1.8 KiB
Go
Raw Normal View History

2018-09-14 13:02:13 +08:00
// Copyright 2017 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://gitee.com/johng/gf.
package ghttp
import (
"gitee.com/johng/gf/g/os/glog"
)
// 设置日志目录
func (s *Server)SetLogPath(path string) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
2018-11-23 09:20:45 +08:00
return
2018-09-14 13:02:13 +08:00
}
if len(path) == 0 {
return
}
s.config.LogPath = path
s.logger.SetPath(path)
2018-09-14 13:02:13 +08:00
}
// 设置是否开启access log日志功能
func (s *Server)SetAccessLogEnabled(enabled bool) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
2018-11-23 09:20:45 +08:00
return
2018-09-14 13:02:13 +08:00
}
s.config.AccessLogEnabled = enabled
}
// 设置是否开启error log日志功能
func (s *Server)SetErrorLogEnabled(enabled bool) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
2018-11-23 09:20:45 +08:00
return
2018-09-14 13:02:13 +08:00
}
s.config.ErrorLogEnabled = enabled
}
// 设置日志写入的回调函数
func (s *Server) SetLogHandler(handler LogHandler) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
2018-11-23 09:20:45 +08:00
return
2018-09-14 13:02:13 +08:00
}
s.config.LogHandler = handler
}
// 获取日志写入的回调函数
func (s *Server) GetLogHandler() LogHandler {
return s.config.LogHandler
}
// 获取日志目录
func (s *Server)GetLogPath() string {
return s.config.LogPath
}
// access log日志功能是否开启
func (s *Server)IsAccessLogEnabled() bool {
return s.config.AccessLogEnabled
}
// error log日志功能是否开启
func (s *Server)IsErrorLogEnabled() bool {
return s.config.ErrorLogEnabled
}