Created
March 15, 2023 20:02
-
-
Save niski84/d681fc9968dc6109b6395fbbf4bb68ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"path/filepath" | |
"runtime" | |
"time" | |
) | |
func main() { | |
exampleLogMessage("This is an example log message!") | |
} | |
func exampleLogMessage(message string) { | |
logLevel := "INFO" | |
timestamp := time.Now().Format("2006-01-02 15:04:05") | |
_, file, line, _ := runtime.Caller(1) | |
file = filepath.Base(file) | |
// Using fmt.Sprintf() to format the log message | |
logMessage := fmt.Sprintf( | |
"╔══[%s]══[%s]══[%s:%d]══╗\n║ %s\n╚═══════════════════════╝", | |
logLevel, timestamp, file, line, message, | |
) | |
// Print the log message | |
log.SetOutput(os.Stdout) | |
log.Println(logMessage) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment