Code snippets with tests and testable examples for the Go programming language

How to include the filename and the line number in a logger output

Snippets Index - Run code on Go playground - Edit

package main

import (

func Example() {
	// You can configure the output format of a logger using
	// flags
	// Use log.LshortfileIf to print the filename without
	// the full path and the line number or
	// Use log.Llongfile to print the filename with
	// the full path and the line number
	// The log.Llongfile example is not included below
	// because playground use different path each time
	log.Println("Hello world")
	// Output:
	// prog.go:20: Hello world

by psampaz - source code - comment below or here