How to use logger on Linux

How to use logger on Linux

The logger command provides an easy way to add log files to /var/log/syslog — from the command line, from scripts, or from other files. In today’s post, we’ll take a look at how it works.

How easy is easy?

This easy. Just type logger <message> on the command line and your message will be added to the end of the /var/log/syslog file.

$ logger comment to be added to log
$ tail -1 /vvar/log/syslog
May 21 18:02:16 butterfly shs: comment to be added to log

Command output

You can also add the output from commands by enclosing the commands in backticks.

$ logger `who`
$ tail -1 /var/log/syslog
May 21 18:02:43 butterfly shs: shs pts/0 2018-05-21 15:57 (192.168.0.15)

Content from a file

The contents of text files can be added by using the -f option. Put the name of the file to be added to the log following the -f option as shown below.

To read this article in full, please click here

div#stuning-header .dfd-stuning-header-bg-container {background-image: url(https://safevoip.co.uk/wp-content/uploads/2017/04/slider.jpg);background-size: initial;background-position: top center;background-attachment: initial;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 650px;}