Using log package in golang

Look! there's a flower!·2024년 10월 4일
0

import

import ( 
   "log"
   "syscall"
   )

File

file, _ = os.OpenFile("app.log",
syscall.O_APPEND|syscall.O_CREATE|syscall.O_WRONLY, 0644)
defer file.Close()
log.SetOutput(file)
log.Println()
log.Printf()

stdout

log.SetOutput(stdout)

Flag

// get flag value and save it before change flags value using SetFlags()
log.Flags()

// date, time, microseconds, filename
// usually filename is not necessary
log.SetFlags(log.Ldate | log.Ltime | log.Lmicrosecons | log.Llongfile)

// in most cases, prefix is not necessary.
log.SetPrefix("App:")

// without log header
log.SetFlags(0)

func LPrintf(fmtText string, args ...interface{}) {
fmt.Printf(fmtText, args...)
}

using time

import ("time")
import ("fmt")
now := time.Now()
fmt.Println(now.Format("20060102 15:04:05"))
fmt.Println(now.Format("2006-01-02 150405"))
fmt.Println(now.Format("20060102 150405"))

profile
Why don't you take a look around for a moment?

0개의 댓글