Search⌘ K
AI Features

Logging Information I

Explore how to write and manage logging information in Go applications using system log files and the log package. Understand UNIX logging levels and facilities, and learn to handle critical errors with log.Fatal and log.Panic functions. This lesson helps you implement effective application logging and error reporting in Go.

Although it is useful to print error messages onscreen, there are times that we need to keep all error messages together and be able to search them when it is convenient for us. In this case, we need to use one or more log files.

Introduction to logging information

Log files

All UNIX systems have their own log files for writing logging information that comes from running servers and programs. Usually, most system log files of a UNIX system can be found under the /var/log directory. However, the log files of many popular services, such as Apache and Nginx, can be found elsewhere, depending on their configuration.

Generally speaking, using a log file to write some information used to be considered a better practice than writing the same output on the screen for two reasons: firstly, because the output does not get lost ...