CLOSELOG(3P)
π CLOSELOG(3P) π β bestie's guide to the POSIX Programmer's Manual
okay so. before we even start, real talk: this page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the Linux behavior, bestie), or the interface might not even be implemented on Linux at all. π just so you know.
β¨ NAME β¨
closelog, openlog, setlogmask, syslog β control system log. that's the whole vibe. logging. managing it. slay.
πΈ SYNOPSIS πΈ
#include <syslog.h>
void closelog(void);
void openlog(const char *ident, int logopt, int facility);
int setlogmask(int maskpri);
void syslog(int priority, const char *message, ... /* arguments */);
π¦ DESCRIPTION π¦
so syslog() shall send a message to an implementation-defined logging facility. and what does that facility do with it? honestly, implementation-defined, babe β it may log it in an implementation-defined system log, write it to the system console, forward it to a list of users, or forward it to the logging facility on another host over the network. so many options, main character energy honestly.
The logged message shall include a message header and a message body. The message header contains at least a timestamp and a tag string. iconic.
The message body is generated from the message and the following arguments in the same manner as if these were arguments to printf(), EXCEPT β and this is the part everyone misses β the additional conversion specification %m shall be recognized. it shall convert no arguments, shall cause the output of the error message string associated with the value of errno on entry to syslog(), and may be mixed with argument specifications of the "%n$" form. If a complete conversion specification with the m conversion specifier character is not just %m, the behavior is undefined. so don't do that. π
A trailing <newline> may be added if needed.
Values of the priority argument are formed by OR'ing together a severity-level value and an optional facility value. If no facility value is specified, the current default facility value is used.
Possible values of severity level include:
LOG_EMERGβ a panic condition. we are PANICKING. π¨LOG_ALERTβ a condition that should be corrected immediately, such as a corrupted system database.LOG_CRITβ critical conditions, such as hard device errors.LOG_ERRβ errors.LOG_WARNINGβ warning messages.LOG_NOTICEβ conditions that are not error conditions, but that may require special handling.LOG_INFOβ informational messages.LOG_DEBUGβ messages that contain information normally of use only when debugging a program.
The facility indicates the application or system component generating the message. Possible facility values include:
LOG_USERβ messages generated by arbitrary processes. This is the default facility identifier if none is specified.LOG_LOCAL0β reserved for local use.LOG_LOCAL1β reserved for local use.LOG_LOCAL2β reserved for local use.LOG_LOCAL3β reserved for local use.LOG_LOCAL4β reserved for local use.LOG_LOCAL5β reserved for local use.LOG_LOCAL6β reserved for local use.LOG_LOCAL7β reserved for local use.
π openlog() π
The openlog() function shall set process attributes that affect subsequent calls to syslog(). The ident argument is a string that is prepended to every message. The logopt argument indicates logging options. Values for logopt are constructed by a bitwise-inclusive OR of zero or more of the following:
LOG_PIDβ log the process ID with each message. This is useful for identifying specific processes. so you know who did it. π΅οΈββοΈLOG_CONSβ write messages to the system console if they cannot be sent to the logging facility. Thesyslog()function ensures that the process does not acquire the console as a controlling terminal in the process of writing the message.LOG_NDELAYβ open the connection to the logging facility immediately. Normally the open is delayed until the first message is logged. This is useful for programs that need to manage the order in which file descriptors are allocated.LOG_ODELAYβ delay open untilsyslog()is called.LOG_NOWAITβ do not wait for child processes that may have been created during the course of logging the message. This option should be used by processes that enable notification of child termination usingSIGCHLD, sincesyslog()may otherwise block waiting for a child whose exit status has already been collected.
The facility argument encodes a default facility to be assigned to all messages that do not have an explicit facility already encoded. The initial default facility is LOG_USER.
The openlog() and syslog() functions may allocate a file descriptor. It is not necessary to call openlog() prior to calling syslog(). you can just rawdog it, fr fr. π
π closelog() π
The closelog() function shall close any open file descriptors allocated by previous calls to openlog() or syslog().
β setlogmask() β
The setlogmask() function shall set the log priority mask for the current process to maskpri and return the previous mask. If the maskpri argument is 0, the current log mask is not modified. Calls by the current process to syslog() with a priority not set in maskpri shall be rejected. The default log mask allows all priorities to be logged. A call to openlog() is not required prior to calling setlogmask(). go off, you don't need permission. π
Symbolic constants for use as values of the logopt, facility, priority, and maskpri arguments are defined in the <syslog.h> header.
π« RETURN VALUE π«
The setlogmask() function shall return the previous log priority mask.
The closelog(), openlog(), and syslog() functions shall not return a value. they said no thoughts, head empty, no return. π«Ά
π ERRORS π
No errors are defined.
The following sections are informative.
π§ EXAMPLES π§
Using openlog()
The following example causes subsequent calls to syslog() to log the process ID with each message, and to write messages to the system console if they cannot be sent to the logging facility.
#include <syslog.h>
char *ident = "Process demo";
int logopt = LOG_PID | LOG_CONS;
int facility = LOG_USER;
...
openlog(ident, logopt, facility);
Using setlogmask()
The following example causes subsequent calls to syslog() to accept error messages, and to reject all other messages.
#include <syslog.h>
int result;
int mask = LOG_MASK (LOG_ERR);
...
result = setlogmask(mask);
Using syslog
The following example sends the message "Thisisamessage" to the default logging facility, marking the message as an error message generated by random processes.
#include <syslog.h>
char *message = "This is a message";
int priority = LOG_ERR | LOG_USER;
...
syslog(priority, message);
πΈ APPLICATION USAGE πΈ
None.
π RATIONALE π
None.
π¦ FUTURE DIRECTIONS π¦
None.
π₯ SEE ALSO π₯
fprintf()
The Base Definitions volume of POSIX.1β2017, <syslog.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! this one came to you from IEEE/The Open Group, 2017 β yeah, 2017, it's vintage, it's a classic, it's giving legacy but make it fashion. π β¨ π log responsibly. mwah. π π¦πΈ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms