Browse Source

Add LogError, LogInfo

Volodymyr Tkach 2 years ago
parent
commit
1635f47daa
1 changed files with 20 additions and 0 deletions
  1. 20 0
      utils/http/logger/logger.go

+ 20 - 0
utils/http/logger/logger.go

@@ -28,6 +28,26 @@ func appendToLogFile(fileName, msg string) error {
 	return nil
 	return nil
 }
 }
 
 
+func LogError(format string, a ...any) {
+	msg := fmt.Sprintf(format, a...)
+	log.Printf("%s", msg)
+	if ErrorLogFile != "" {
+		if err := appendToLogFile(ErrorLogFile, time.Now().Format("2006/01/02 15:04:05")+" "+msg); err != nil {
+			log.Printf("%s\n", err.Error())
+		}
+	}
+}
+
+func LogInfo(format string, a ...any) {
+	msg := fmt.Sprintf(format, a...)
+	log.Printf("%s", msg)
+	if AccessLogFile != "" {
+		if err := appendToLogFile(AccessLogFile, time.Now().Format("2006/01/02 15:04:05")+" "+msg); err != nil {
+			log.Printf("%s\n", err.Error())
+		}
+	}
+}
+
 func LogInternalError(err error) {
 func LogInternalError(err error) {
 	log.Printf("%s\n", err.Error())
 	log.Printf("%s\n", err.Error())
 	if RollBarEnabled && !RollBarSkipErrors.contain(err.Error()) {
 	if RollBarEnabled && !RollBarSkipErrors.contain(err.Error()) {