Skip to content

Instantly share code, notes, and snippets.

@niski84
Created March 15, 2023 20:02
Show Gist options
  • Save niski84/d681fc9968dc6109b6395fbbf4bb68ad to your computer and use it in GitHub Desktop.
Save niski84/d681fc9968dc6109b6395fbbf4bb68ad to your computer and use it in GitHub Desktop.
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