All notes



#---------- Debug related

# Check the configuration files for any syntax errors on both the client and the server using
syslog-ng --syntax-only
syslog-ng --syntax-only -f /etc/syslog-ng/syslog-ng.conf

# use tcpdump or a similar packet sniffer tool on the client to verify that the messages are sent correctly, and on the server to verify that it receives the messages.

# Run in foreground, and display debug messages
syslog-ng -Fevd

# Turn on --verbose or --debug command-line options for more-detailed log messages. You can enable these messages without restarting syslog-ng using:
syslog-ng-ctl verbose --set=on



syslog-ng-ctl verbose/trace/debug --set=on
syslog-ng-ctl stats
syslog-ng-ctl reload

# NOTE: this command needs a socket open:
syslog-ng-ctl stats
# Error connecting control socket, socket='/var/syslog-ng.ctl', error='No such file or directory'


logger System rebooted
logger -p local0.notice -t HOSTIDM -f /dev/idmc
logger -n System rebooted

# "-t rails-projname" sets the program name.
# "-p user.debug" sets the facility and priority level.
logger -p user.debug -t rails-projname "Hello world"

##### Common options.

-P, --port port
  Use the specified port.
-f, --file file
  Log the contents of the specified file.  This option cannot be combined with a command-line message.
-p, --priority priority
-t, --tag tag
  Mark every line to be logged with the specified tag. "tag" is usually the "program name" field.

##### Used in debugging.

-s, --stderr
  Output the message to standard error as well as to the system log.

##### Others

-T, --tcp
  Use stream (TCP) only.  By default the connection is tried to the syslog-conn port defined in /etc/services, which is often 601.

-d, --udp
  Use datagram (UDP) only.

-u, --socket socket
  Write to the specified socket instead of to the builtin syslog routines.

-n, --server server
  Write  to the specified remote syslog server instead of to the builtin syslog routines.  Unless --udp or --tcp is specified, logger will first try to use UDP, but if thist fails a TCP connection is attempted.

Log buffer

You can configure syslogd (and rsyslog at least) not to sync the log files after a log message by prepending a "-" to the log file path in the configuration file. This speeds up performance at the expense of the danger that log messages could be lost in a crash.

wcfNote: if you just want to debug for syslog.conf, use "logger -s" option instead.

Macro syslog-ng macros.

  The name of the facility (for example, kern) that sent the message.
  The numerical code of the facility (for example, 0) that sent the message.
  The priority of the message, for example, error. For the textual representation of this value, use the ${LEVEL} macro.

Global options reference options.


Accepted values:	rfc3164 | bsd | rfc3339 | iso
Default:	rfc3164

RFC 3164

The stackExchange states that:

RFC3164 does not include a year in the timestamp portion of a log entry.
RFC5424 is supposed to make RFC3164 obsolete.
When you eventually switch to systemd (resistance is futile), you can use journalctl's -o short-iso option to get real ISO 8601 timestamps.



Files under /var/log/

According to /etc/syslog.conf, default /var/log/kern.log captures only the kernel's messages of any loglevel; i.e. the output of dmesg.

/var/log/messages instead aims at storing valuable, non-debug and non-critical messages. This log should be considered the "general system activity" log.

/var/log/syslog in turn logs everything, except auth related messages.

Other insteresting standard logs managed by syslog are /var/log/auth.log, /var/log/mail.log.

Regarding your question: if you need solely kernel messages log, use the kern.log or call dmesg.

dmesg vs /var/log/messages dmesg vs /var/log/messages.

dmesg prints the contents of the ring buffer. This information is also sent in real time to syslogd or klogd, when they are running, and ends up in /var/log/messages; when dmesg is most useful is in capturing boot-time messages from before syslogd and/or klogd started

filter filter's functions.

Wildcards in filters syslog-ng regexp.

The host(), match(), and program() filter functions accept regular expressions as parameters. The exact type of the regular expression to use can be specified with the type() option. By default, syslog-ng OSE uses PCRE regular expressions.

message("^(.+)\\1$" type("posix"))

# If you do not need regular expressions, only wildcards, use type(glob):
filter f_wildcard {host("myhost*" type(glob));};

Combine filters

filter demo_filter { not host("example1") and not host("example2"); };
# Alternatively, you can use parentheses to avoid this confusion:
filter demo_filter { not (host("example1") or host("example2")); };


It accepts both the name and the numerical code of the facility or the importance level. Facility codes 0-23 are predefined.

# range with facility names

local facility

source s_udp  {
  udp( ip( port(514) );

destination d_application { file("/var/log/application.log"); };
destination d_syslog { file("/var/log/syslog"); };

filter f_my_servers { host(h-001) or host(h-002) or host(h-003); };
filter f_test1  { facility(local5) and filter(f_my_servers); };
filter f_test2 { filter(f_my_servers); };

log { source(s_udp); filter(f_test1); destination(d_application);
flags(final); };
log { source(s_udp); filter(f_test2); destination(d_syslog); flags(final);

# "logger -p test" outputs to /var/log/application.log.


Match messages by using a regular expression against the program name field of log messages.

For example, "rails-myproj-3586701d6057" here is the program field:

2017-10-11T05:13:00+00:00 [user:debug] rails-myproj-3586701d6057[java-sdk-http-connection-reaper] org.apache.http.impl.conn.PoolingHttpClientConnectionManager Closing connections idle longer than 60 SECONDS

priority or level

The level() filter accepts the following levels: emerg, alert, crit, err, warning, notice, info, debug.

source sources.

# Receives messages on the 1999 TCP port and the 1999 UDP port of the interface having the IP address.
source s_demo_two_drivers {
  network(ip( port(1999));
  network(ip( port(1999) transport("udp"));

source s_demo {
  internal(); # Messages generated by syslog-ng. wcfNote: receives messages from klogd(8)? See "logging in Linux" below.
  network(transport("udp")); # Messages arriving to the 514/UDP port of any interface of the host.
  unix-dgram("/dev/log"); # Messages arriving to the /dev/log socket. You may use "unix-stream()" for stream socket e.g. tcp.

# Setting default priority and facility
# If the message received does not have a proper syslog header, it will use the default settings.
source headerless_messages { network(default-facility(syslog) default-priority(emerg)); };


Logging in Linux understanding logging in Linux.

The kernel logs messages (using the printk() function) to a ring buffer in kernel space. These messages are made available to user-space applications in two ways:

There are two main applications that read (and, to some extent, can control) the kernel's ring buffer:

In user space, there's syslogd(8). It has three sources:

It then writes these messages to some files in /log, or to named pipes, or sends them to some remote hosts (via the syslog protocol, on UDP port 514).

User-space applications normally use the libc function syslog(3) to log messages. libc sends these messages to the UNIX domain socket /dev/log (where they are read by syslogd(8)).

Other daemons (such as rsyslog and syslog-ng, as you mention) can replace the plain syslogd(8), and do all sorts of nifty things, like send messages to remote hosts via encrypted TCP connections, provide high resolution timestamps, and so on. And there's also systemd, that is slowly phagocytosing the UNIX part of Linux.

systemd has its own logging mechanisms ( /dev/log is missing):

# Managed by systemd-journald.service, "Symlinks=/dev/log", similar to:
sudo ln -s /run/systemd/journal/dev-log /dev/log