This commit is contained in:
ge
2026-01-03 15:10:39 +03:00
commit 0b5c70550a
8 changed files with 193 additions and 0 deletions

94
syslog.c.v Normal file
View File

@@ -0,0 +1,94 @@
module syslog
#include <syslog.h>
fn C.openlog(&char, i32, i32)
fn C.syslog(i32, &char, ...voidptr)
fn C.closelog()
/*
Values for option
*/
pub const log_cons = C.LOG_CONS
pub const log_ndelay = C.LOG_NDELAY
pub const log_nowait = C.LOG_NOWAIT
pub const log_odelay = C.LOG_ODELAY
pub const log_perror = C.LOG_PERROR
pub const log_pid = C.LOG_PID
/*
Values for facility
*/
pub const log_auth = C.LOG_AUTH
pub const log_authpriv = C.LOG_AUTHPRIV
pub const log_cron = C.LOG_CRON
pub const log_daemon = C.LOG_DAEMON
pub const log_ftp = C.LOG_FTP
pub const log_kern = C.LOG_KERN
pub const log_local0 = C.LOG_LOCAL0
pub const log_local1 = C.LOG_LOCAL1
pub const log_local2 = C.LOG_LOCAL2
pub const log_local3 = C.LOG_LOCAL3
pub const log_local4 = C.LOG_LOCAL4
pub const log_local5 = C.LOG_LOCAL5
pub const log_local6 = C.LOG_LOCAL6
pub const log_local7 = C.LOG_LOCAL7
pub const log_lpr = C.LOG_LPR
pub const log_mail = C.LOG_MAIL
pub const log_news = C.LOG_NEWS
pub const log_syslog = C.LOG_SYSLOG
pub const log_user = C.LOG_USER
pub const log_uucp = C.LOG_UUCP
/*
Values for level
*/
pub enum Level {
emerg = C.LOG_EMERG
alert = C.LOG_ALERT
crit = C.LOG_CRIT
err = C.LOG_ERR
warn = C.LOG_WARNING
notice = C.LOG_NOTICE
info = C.LOG_INFO
debug = C.LOG_DEBUG
}
@[params]
pub struct OpenParams {
pub:
ident string
option int
facility int = log_user
}
// open opens a system log for program. See also openlog(3).
pub fn open(p OpenParams) Syslog {
C.openlog(&char(p.ident.str), i32(p.option), i32(p.facility))
return Syslog{
OpenParams: p
is_opened: true
}
}
struct Syslog {
OpenParams
pub mut:
is_opened bool
}
// send sends a message of level `lvl` to system journal. See also syslog(3).
pub fn (s Syslog) send(lvl Level, msg string) {
C.syslog(i32(lvl), c'%s', &char(msg.str))
}
// close closes the system journal. See also closelog(3).
pub fn (mut s Syslog) close() {
if s.is_opened {
C.closelog()
s.is_opened = false
}
}