logger

send a message to syslog system

linux

Text in this font/color apply to the xxxx version

logger [ -isdhV ] [-p pri | facility.level] [-n server] [-P port] [-t tag] [-u socket] [-f file] [--] [message]

Send messages to the syslog subsystem to be processed by syslogd daemon as per /etc/syslog.conf, frequently writting them to /var/log.

Without message or -f, standard input is logged. With no stdin no message is sent.

-p
--priority facility.level | 0:7
Examplea -p local3.info logs the message as informational in the local3 facility.
-p 9 uses emerg Default: user.notice.
facilities: cron, ftp, lpr, kern, mail, news, syslog, uucp,
auth, authpriv (for security information of a sensitive nature),security(deprecated synonym for auth),
daemon, user, local0, 1 … 6, local7
levels: emerg, panic, alert, crit, err, error, warning, warn, notice, info, debug

-f
--file file
Log the contents of file
-e
--skip-empty
empty lines are ignored when processing files. (A line of only whitespace is NOT considered empty).
-n
--server server
remote syslog server that the message is sent to. Uses UDP with failover to TCP unless --udp or --tcp is specified,
-- End the arguments allowng the message to start with a hyphen (-).
-s
--stderr
stderr also receives message
-P
--port port
Default to syslog for UDP and to syslog-conn for TCP , often 514 .
-d
--udp
use UDP
-d
--udp
Use UDP datagram. Default TCP.
-T
--tcp
use TCP only. Default syslog-conn port defined in /etc/services, often 601.
--journald[=file] systemd journal entry from file. Default:standard input.
Lines must begin with a field that is accepted by journald; see systemd.journal-fields, use MESSAGE_ID to make finding entries easy. Examples:
 logger --journald <<+++
          MESSAGE_ID=67feb6ffbaf24c5cbec13c008dd72309
          MESSAGE="The dogs bark, but the caravan goes on."
          DOGS=bark
          CARAVAN=goes on
          +++

 logger --journald=entry.txt 
Ignores other options, such as priority ( which can be in provided using PRIORITY field. )

journalctl displays date, time, host, subsystem, PID and message.

-- Logs begin at Fri 2023-05-26 12:29:56 EDT, end at Fri 2023-05-26 17:36:23 EDT. --
May 26 12:29:56 dapi2 kernel: Booting Linux on physical CPU 0x0
May 26 12:29:56 dapi2 kernel: Linux version 5.10.103+ (dom@buildbot) 
        (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld 
Use journalctl --output json-pretty to see all fields in JSON format.

> journalctl --output json-pretty 
{
        "_BOOT_ID" : "a7e86d",
        "MESSAGE" : "Booting Linux on physical CPU 0x0",
        "__REALTIME_TIMESTAMP" : "1685118596405396",
        "SYSLOG_IDENTIFIER" : "kernel",
        "SYSLOG_FACILITY" : "0",
        "_TRANSPORT" : "kernel",
        "__MONOTONIC_TIMESTAMP" : "9505538",
        "PRIORITY" : "6",
        "_HOSTNAME" : "dapi2"
}
{
        "_MACHINE_ID" : "441e2a1e2",
        "_HOSTNAME" : "dapi2",
        "__REALTIME_TIMESTAMP" : "1685118596406636",
        "PRIORITY" : "5",
        "_BOOT_ID" : "a7e86d",
        "SYSLOG_IDENTIFIER" : "kernel",
        "SYSLOG_FACILITY" : "0",
        "_TRANSPORT" : "kernel",
        "_SOURCE_MONOTONIC_TIMESTAMP" : "0",
        "MESSAGE" : "Linux version 5.10.103+ (dom@buildbot) … 8.4.0, GNU ld '
}
--prio-prefix <fp> fp facility and level using facility * 8 + level.
facility defaults to specified by -p

Example: local0.info: facility 16 and level 6, 16*8+6 becomes <134>.

Does not affect a command-line message.
With --prio-prefix, lines without characters after prefix are ignored.

--rfc3164 <facility*8+level> Mon dd hh:mm:ss hostname pgm content
--sd-id name[@digits] Structured data element ID for an RFC 5424 message header.
Must be before --sd-param to introduce a new element.
The ID (name@digits ) is case-sensitive and uniquely identifies the type and purpose of the element.
The same ID must not exist more than once in a message.
@digits is required for user-defined non-standardized IDs.

logger generates the timeQuality standardized element only.
RFC 5424 describes the elements origin (with parameters ip, enterpriseId, software and swVersion) and meta (with parameters sequenceId, sysUpTime and languagei). These element IDs may be specified without @digits

--msgid msgid RFC5424 MSGID field. A space is not permitted in msgid.
--sd-param name="value" Structured Data element parameter.
Example:
 logger --rfc5424 --sd-id zoo@123        \ 
                  --sd-param tiger=\"hungry\"   \ 
                  --sd-param zebra=\"running\"  \
                  --sd-id manager@123           \
                  --sd-param onMeeting=\"yes\" "African area status" 
produces:
 <13>1 2015-10-01T14:07:59.168662+02:00 ws kzak - - 
    [timeQuality tzKnown="1" isSynced="1" syncAccuracy="218616"]
    [zoo@123 tiger="hungry" zebra="running"]
    [manager@123 onMeeting="yes"] African area status
--rfc5424[notq|,notime,|
nohost]
submit messages to a remote server. Default.
notq |
--sd-id TimeQuality
time-quality is ommitted
Shows if the local clock was synchronized and the maximum number of microseconds the timestamp might be off.
notime suppresses the timestamp (implies notq)
nohostsuppress gethostname(2) information
--size maxsize maximum message size including the header. Default 1KiB.
--octet-count Use the RFC 6587 octet counting framing method for sending messages.
Default is no framing on UDP, and RFC6587 non-transparent framing (also known as octet stuffing) on TCP.
--id[=id] id is used for the PID in the message.

use --id=$$ (PPID)

--socket-errors
    [=on|off|auto]
Output errors about socket connections.
With auto logger will detect (if the init process is systemd) and if so the assumption is made that /dev/log can be used early at boot.
default auto.
When errors are not enabled lost messages are not communicated and will result in success return value !
-t
--tag tag
Mark every line with tag. Default name of the user
-u
--socket socket
Instead of the system log socket.
--no-act No system log writing and remove the connection or the journal.
Used with --stderr for testing purposes.
-i logger's PID is included in the message (probally not helpful)
-V
--version
 
-h
--help
 

Return value

0 on success, and 0 if an error occurs.

FACILITIES AND LEVELS

Valid facility names(numbers) :

 auth
 authpriv   for security information of a sensitive nature
 cron(9,15)
 daemon(3)
 ftp(11)
 kern (0)      cannot be generated from userspace process, automatically converted to user.
 lpr(6)
 log audit(13), log alert(14)
 mail(2) 
 news(7)
 ntp(12)
 syslog(5)
 user(1)
 uucp(8)
 local0 (16)
 …
 local7(23)
 security (4)  deprecated synonym for auth

Valid level names(numbers) :

 emerg(0), alert(1), crit(2), err(3), warning(4), notice(5), info(6), debug(7) 
depricated: error, warn and panic
For the priority order and intended purposes of these facilities and levels, see syslog(3).

Examples

       logger System rebooted
       logger --priority local0.notice -t HOSTIDM -f /dev/idmc
       logger --server loghost.example.com System rebooted

See

journalctl, syslog(3), systemd.journal-fields(7)

Example:

  1. Run myUpdater.sh
  2. Send a syslog notice that it ran containing the last line of the stdout
  3. Send the log file to the syslog with a priority of info
  4. If there return code indicated a problem,
    send the stderr to syslog with priority of error
    myUpdater.sh 1> /tmp/myUpdater.log 2> /tmp/myupdater.err
    rc=$?
     tail -n1 /tmp/myUpdater.log | logger -p local3.notice 
     logger -p local3.info -f /tmp/myUpdater.log
    if [ $rc != 0 ]; then  logger -p local3.err  -f /tmp/myUpdater.err -s 
     fi 

    exits 0 on success, and >0 if an error occurs.

    logger System rebooted

    logger --priority local0.notice --tag HOSTIDM --file rootStatNotes

    For the priority order and intended purposes of these levels, See syslog(BSDactually Mac OSX ; darwin), syslogd(8)

    syslog(3), syslogd(8)

    Best Practices by Dan Gunter, Lawrence Berkeley National Laboratory

    Some implementations only include -i -s -f -p -t -u!

    Testing

    Generate user.notice (default) entries : telnet logserver-host 514
    message to be logged
    another

    enter ^] to enter telnet command mode.

    Or use nc

    echo '173 <165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ' \
    ' ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] An app event log entry...' |\
    nc 127.0.0.1 6514

    RFC 5424 (Obsoletes: 3164) receivers can process 4KiB.

    rfc3164

    Summary of RFC 3164 The BSD syslog Protocol August 2001

    The MSG part has the TAG field and the CONTENT field.
    The value in the TAG field will be the name of the program or process that generated the message.
    The CONTENT contains the details of the message.
        This has traditionally been a freeform message that gives some detailed information of the event.
    The TAG is a string of ABNF alphanumeric characters that MUST NOT exceed 32 characters.
        Any non-alphanumeric character will terminate the TAG
    The left square bracket ("["), a colon (":"), or a space is frequently the first character of the CONTENT field.
    This is explained in more detail in Section 5.3.

    Errors

    logger: journald entry could not be written

    See syslog rsyslog.com