The Linux administrator must be able to read and understand the different types of messages generated by all Linux systems to fix the problem. These messages, called logs, are triggered by Linux and the applications running on it. Linux constantly creates, saves, and processes these logs using various configuration files, programs, commands, and daemons. If you know how to read these files and make optimal use of the various commands that we will mention in this guide, you can solve your problems as a professional!
It is important to note that Linux stores its log files in the / var / log directory in text format.
View Syslogs in Ubuntu
To cover the essence of the problem or to see if your application or system works as needed, you can view the system log files either graphically or through the command line in the following ways:
- Gnome Logs Utility (Graphics)
- Log File Viewer Utility (Graphics)
- Linux Terminal (Command Prompt)
View Log Files Through Gnome Logs
Logs is the default utility that ships with the latest versions of Ubuntu , such as Ubuntu 18.04 LTS (Bionic Beaver). To access it,
A type logs to hell with Ubuntu:
You can see the open utility “Logs” with the ability to view logs for applications, systems, security and equipment.
Click on the system tab for viewing system logs:
Here you can view all system logs, as well as the time they were created. Through this window you can perform the following actions:
- Display the contents of the log by clicking on it.
- Find the story by clicking the search icon and entering keywords in the search bar. The search bar also offers a number of filters that you can apply to specify exactly which (Select the Log field to filter logs by it) and when (Select the range of timestamps of the log entries to be displayed) that you want to see:
- You can also export logs to a file by clicking the export button located in the upper right corner of the logs window. You can then save the log file by specifying a name and location.
Through the log file viewer
The log file viewer is the default utility that ships with older versions of Ubuntu. If your version of Ubuntu does not have this application by default, you can download and install it using Ubuntu Software.
To access the log file viewer:
- To come in View Journal p in Ubuntu Dash
- If you installed this program through Ubuntu Software, you can run it by searching the Ubuntu software as follows, and then clicking launch button:
Viewing the log file will look like this:
The left pane of the window shows the number of log categories by default, and the right pane shows a list of logs for the selected category.
Click on the syslog tab for viewing system logs. You can search for a specific log using Ctrl + F control, and then enter the keyword. When a new log event is generated, it is automatically added to the list of logs, and you can see it in bold. You can also filter your logs through filters The menu is located on the top menu bar.
To view the log for a specific application, click open option from file menu. Following Open magazine The log selection window will open:
Click on the log file and click open , Now you can view the logs from the selected log file in the log file viewer.
View log files through the terminal
You can also view system logs through the command line, i.e. the Ubuntu terminal.
Open Terminal and enter the following command:
This command retrieves all messages from the kernel buffer. You can see the result as follows:
You will see that this is a lot of information. This information will be useful only if we apply some filters to view what we want to see.
Setting up dmesg output
- To see messages at your own pace, use the following command:
$ dmesg | smaller
This command will only display a certain number of messages on the screen. You can press Enter to go to the next message, or press Q to exit the command.
- To find a message containing a specific keyword, use the following command:
$ dmesg |grep
For example, if you want to find all messages containing the word core, you can use the following command:
$ dmesg |grep core
The terminal will now display only those messages that contain the word “core” in red.
Open the log file with the cat command
The dmesg command opens all the logs from the / var / log directory. To open the log file from another location, use the following command:
$ cat [location]
$ cat /var/log/syslog
This command will print the logs from the syslog file to the screen. You will again notice that this command prints all the information, and viewing it is not easy. Here you can also use the grep and less filters to display the desired result as follows:
$ cat |grep [location]
$ cat |less [location]
Sometimes we need to write user messages to the system log as part of the troubleshooting process. Gnome Log and Log File Viewer are designed to display a customized message that you can write through the Terminal.
Open a Ubuntu terminal and enter the following command:
$ logger “This is a custom message”
You can see a custom log message at the end of the log list shown above in the graphical log file viewer.
You can also use the logger command in a script to provide additional information. In this case, please use the following command in your script:
$ logger -t scriptname “This is a custom message”
By practicing with this tutorial, you can learn how to troubleshoot problems in the system and applications by accessing and understanding system logs.
How to view syslog files in Ubuntu 18.04 LTS