Skip to content Skip to sidebar Skip to footer

Read a Token in Live Log File Python

How can I see the content of a log file in real time in Linux? Well there are a lot of utilities out at that place that can help a user to output the content of a file while the file is changing or continuously updating. Some of the most known and heavily used utility to display a file content in existent time in Linux is the tail command (manage files effectively).

Read As well: 4 Skilful Open Source Log Monitoring and Management Tools for Linux

1. tail Command – Monitor Logs in Real Fourth dimension

As said, tail command is the most common solution to display a log file in existent fourth dimension. However, the command to display the file has two versions, every bit illustrated in the beneath examples.

In the first example the control tail needs the -f argument to follow the content of a file.

$ sudo tail -f /var/log/apache2/admission.log                
Monitor Apache Logs in Real Time
Monitor Apache Logs in Real Time

The second version of the command is really a command itself: tailf. You won't need to use the -f switch considering the control is congenital-in with the -f argument.

$ sudo tailf /var/log/apache2/access.log                
Real Time Apache Logs Monitoring
Real Time Apache Logs Monitoring

Usually, the log files are rotated frequently on a Linux server by the logrotate utility. To watch log files that become rotated on a daily base you can employ the -F flag to tail command.

Read As well: How to Manage System Logs (Configure, Rotate and Import Into Database) in Linux

The tail -F volition go on rails if new log file beingness created and will showtime following the new file instead of the old file.

$ sudo tail -F /var/log/apache2/access.log                

Yet, past default, tail control will display the last 10 lines of a file. For instance, if you desire to watch in real fourth dimension only the last 2 lines of the log file, employ the -north file combined with the -f flag, equally shown in the below case.

$ sudo tail -n2 -f /var/log/apache2/admission.log                
Watch Last Two Lines of Logs
Lookout Terminal 2 Lines of Logs

2. Multitail Command – Monitor Multiple Log Files in Real Time

Another interesting command to display log files in real fourth dimension is multitail command. The name of the control implies that multitail utility tin monitor and go along track of multiple files in real time. Multitail also lets you navigate back and forth in the monitored file.

To install mulitail utility in Debian and RedHat based systems issue the below control.

$ sudo apt install multitail   [On Debian & Ubuntu] $ sudo yum install multitail   [On RedHat & CentOS] $ sudo dnf install multitail   [On Fedora 22+ version]                

To display the output of two log file simultaneous, execute the command as shown in the below case.

$ sudo multitail /var/log/apache2/access.log /var/log/apache2/fault.log                
Multitail Monitor Logs
Multitail Monitor Logs

3. lnav Command – Monitor Multiple Log Files in Real Time

Another interesting control, similar to multitail command is the lnav control. Lnav utility tin can as well sentry and follow multiple files and display their content in real time.

To install lnav utility in Debian and RedHat based Linux distributions by issuing the below command.

$ sudo apt install lnav   [On Debian & Ubuntu] $ sudo yum install lnav   [On RedHat & CentOS] $ sudo dnf install lnav   [On Fedora 22+ version]                

Watch the content of 2 log files simultaneously past issuing the command equally shown in the below example.

$ sudo lnav /var/log/apache2/access.log /var/log/apache2/error.log                
lnav - Real Time Logs Monitoring
lnav – Real Time Logs Monitoring

4. less Command – Display Real Fourth dimension Output of Log Files

Finally, you can display the live output of a file with less command if y'all blazon Shift+F.

Every bit with tail utility, pressing Shift+F in a opened file in less will start following the end of the file. Alternatively, you can also start less with less +F flag to enter to live watching of the file.

$ sudo less +F  /var/log/apache2/access.log                
Watch Logs Using Less Command
Watch Logs Using Less Command

That's It! You may read these following manufactures on Log monitoring and management.

  1. Manage Files Finer using head, tail and cat Commands in Linux
  2. How to Setup and Manage Log Rotation Using Logrotate in Linux
  3. Petiti – An Open Source Log Analysis Tool for Linux SysAdmins
  4. How to Query Audit Logs Using 'ausearch' Tool on CentOS/RHEL
  5. Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]

In this article, we showed how to lookout information being appended in log files in real-fourth dimension on the terminal in Linux. You can ask any questions or share your thoughts concerning this guide via the comment form below.

If Y'all Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and well-nigh trusted community site for whatsoever kind of Linux Articles, Guides and Books on the spider web. Millions of people visit TecMint! to search or scan the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a java ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

barbeeaftearany.blogspot.com

Source: https://www.tecmint.com/watch-or-monitor-linux-log-files-in-real-time/

Post a Comment for "Read a Token in Live Log File Python"