实现基础web服务器
This commit is contained in:
@@ -5,6 +5,7 @@ package logs
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Logger 代表日志记录器结构
|
||||
@@ -16,26 +17,26 @@ type Logger struct {
|
||||
// NewLogger 创建并返回一个新的日志记录器实例
|
||||
func NewLogger() *Logger {
|
||||
return &Logger{
|
||||
logger: log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile),
|
||||
logger: log.New(os.Stdout, "", 0),
|
||||
}
|
||||
}
|
||||
|
||||
// Info 记录信息级别日志
|
||||
func (l *Logger) Info(message string) {
|
||||
l.logger.Printf("[INFO] %s", message)
|
||||
l.logger.Printf("[INFO] %s %s", time.Now().Format(time.RFC3339), message)
|
||||
}
|
||||
|
||||
// Error 记录错误级别日志
|
||||
func (l *Logger) Error(message string) {
|
||||
l.logger.Printf("[ERROR] %s", message)
|
||||
l.logger.Printf("[ERROR] %s %s", time.Now().Format(time.RFC3339), message)
|
||||
}
|
||||
|
||||
// Debug 记录调试级别日志
|
||||
func (l *Logger) Debug(message string) {
|
||||
l.logger.Printf("[DEBUG] %s", message)
|
||||
l.logger.Printf("[DEBUG] %s %s", time.Now().Format(time.RFC3339), message)
|
||||
}
|
||||
|
||||
// Warn 记录警告级别日志
|
||||
func (l *Logger) Warn(message string) {
|
||||
l.logger.Printf("[WARN] %s", message)
|
||||
l.logger.Printf("[WARN] %s %s", time.Now().Format(time.RFC3339), message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user