LoginSignup
1
0

More than 3 years have passed since last update.

Go言語のlogパッケージ

Posted at

logパッケージを使用すると日付と時間とメッセージを表示させることができる。

log.Print

  • log.Print
  • log.Printf
  • log.Println

3種類あるが、内容的にはfmtと同じ、先頭に日付が入るだけ。

package main

import("log")

func main(){
    log.Print("ログやで")
}

log.Fatal

何かエラーが発生した場合にログを表示してプログラムを終了させたい場合はFatalを使用する。Fatalも3種類ある。

  • Fatal
  • Fatalf
  • Fatalln
func main(){
    r, err := ioutil.ReadFile("text.text")

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(r)
}

// 2020/01/31 15:39:11 open text.text: The system cannot find the file specified.
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0