SYSLOG(3lua)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’œ SYSLOG(3lua) β€” the Lua glow-up

okay so bestie, this is the syslog page from the LOCAL manual set β€” like, section 3lua, the Lua-bindings corner of the man-page universe. It's the one that lets your Lua code talk to syslog(3). Yes. That syslog. The ✨real✨ one. Buckle up πŸŽ€


🌸 NAME 🌸

syslog β€” get at all that syslog(3) functionality straight from Lua, no cap πŸ’…


✨ SYNOPSIS ✨

local syslog = require 'syslog'

syslog.openlog(ident, logopt, facility)
syslog.syslog(priority, message)
syslog.closelog()
oldmask = syslog.setlogmask(maskpri)

That's it. Four calls. Iconic behaviour, honestly 🫢


πŸ’– DESCRIPTION πŸ’–

The syslog Lua binding hands you access to syslog(3) functionality. Like, the whole point. Logging from Lua, but the real logging, the system kind. Obsessed πŸ¦‹

🧚 syslog.openlog(ident, logopt, facility)

This one is for when you want more specialized processing of the messages that syslog.syslog() sends out. Fancy. Main character energy.

The parameter ident is a string that gets prepended to every single message. Every one. It's the little name tag your logs wear πŸŽ€

The logopt argument is a bit field specifying logging options, and you form it by adding together one or more of these bad boys:

  • syslog.LOG_CONS β€” if syslog.syslog() can't pass the message along to syslogd(8), it's gonna try writing that message to the console (/dev/console). Backup plan activated πŸ’€
  • syslog.LOG_NDELAY β€” open the connection to syslogd(8) immediately. Normally that open is delayed until the very first message gets logged. This one's useful for programs that need to manage the order in which file descriptors get allocated. fr fr, it matters πŸ”₯
  • syslog.LOG_PERROR β€” writes the message to standard error output as well as to the system log. Double posting, but make it intentional ✨
  • syslog.LOG_PID β€” logs the process id with each message, which is genuinely so useful for identifying instantiations of daemons. (And just so we're clear: this PID gets placed within brackets between the ident and the message. tiny detail, big deal πŸŽ€)

Then the facility parameter encodes a default facility assigned to all messages that don't already have an explicit facility encoded. The menu:

  • syslog.LOG_AUTH β€” the authorization system: login(1), su(1), getty(8), etc. 🫢
  • syslog.LOG_AUTHPRIV β€” same as LOG_AUTH, except it gets logged to a file readable only by selected individuals. exclusive. iykyk πŸ’…
  • syslog.LOG_CRON β€” the cron daemon: cron(8) ⏰
  • syslog.LOG_DAEMON β€” system daemons, like routed(8), that aren't provided for explicitly by other facilities
  • syslog.LOG_FTP β€” the file transfer protocol daemon: ftpd(8) πŸ“
  • syslog.LOG_KERN β€” messages generated by the kernel. Heads up bestie: these cannot be generated by any user processes. Not your lane, not your problem πŸ™ˆ
  • syslog.LOG_LPR β€” the line printer spooling system: lpr(1), lpc(8), lpd(8), etc. πŸ–¨οΈ
  • syslog.LOG_MAIL β€” the mail system πŸ“¬
  • syslog.LOG_NEWS β€” the network news system πŸ“°
  • syslog.LOG_SYSLOG β€” messages generated internally by syslogd(8). self-referential queen πŸ‘‘
  • syslog.LOG_USER β€” messages generated by random user processes. This is the default facility identifier if none is specified, so if you're lazy (same), this is where you land πŸ’œ
  • syslog.LOG_UUCP β€” the uucp system
  • syslog.LOG_LOCAL0 β€” reserved for local use. Similarly for syslog.LOG_LOCAL1 through syslog.LOG_LOCAL7 β€” you get the whole little family, seven siblings and all 🌈

🌟 syslog.syslog(priority, message)

The syslog() function writes message to the system message logger. Then that message gets written to the system console, log files, logged-in users, or forwarded to other machines as appropriate (peep syslogd(8) for the how). It's giving distribution network ✨

The message gets tagged with priority, and priorities are encoded as a facility plus a level. The facility describes which part of the system is generating the message. The level comes from this list, and it's ordered β€” high to low, bestie:

  • syslog.LOG_EMERG β€” a panic condition. This one is normally broadcast to all users. 🚨 everyone's getting this text
  • syslog.LOG_ALERT β€” a condition that should be corrected immediately, like, say, a corrupted system database. fix it NOW 😭
  • syslog.LOG_CRIT β€” critical conditions, e.g., hard device errors
  • syslog.LOG_ERR β€” errors
  • syslog.LOG_WARNING β€” warning messages
  • syslog.LOG_NOTICE β€” conditions that aren't error conditions but should possibly be handled specially. the "hmm πŸ‘€" tier
  • syslog.LOG_INFO β€” informational messages
  • syslog.LOG_DEBUG β€” messages that contain information normally of use only when debugging a program πŸ”

πŸŽ€ syslog.closelog()

Use this to close the log file. That's the whole thing. Bye πŸ‘‹

πŸ¦‹ oldmask = syslog.setlogmask(maskpri)

The setlogmask() function sets the log priority mask to maskpri and returns the previous mask β€” so you get the old one back as oldmask, cute little handoff 🫢. Calls to syslog() with a priority that isn't set in maskpri get rejected. Just so you know πŸ’€


πŸ”— SEE ALSO πŸ”—

lua(1), luac(1), syslog(3), intro(3lua), syslogd(8)

the whole friend group, go say hi πŸ’–


⭐ HISTORY ⭐

A syslog Lua binding manual appeared in NetBSD 7.0</> . and now it's here, being explained to you in a group chat. glow-up complete ✨


πŸ‘‘ AUTHORS πŸ‘‘

The syslog Lua binding was written by Marc Balmer <mbalmer@NetBSD.org>. king behaviour, we love to see it πŸ«ΆπŸ†


ngl bestie, log responsibly β€” LOG_EMERG is not a vibe for casual use πŸ’…

Debian Β· January 7, 2014 β€” that's the source and the date, mwah, catch you in the logs πŸŽ€πŸ’œπŸ¦‹

πŸ“¦ where this page comes from