Skip to content

Instantly share code, notes, and snippets.

@jsuwo
Created October 21, 2015 20:45
Show Gist options
  • Save jsuwo/a01166bd0f6e66bb070f to your computer and use it in GitHub Desktop.
Save jsuwo/a01166bd0f6e66bb070f to your computer and use it in GitHub Desktop.
Simple syslog example
#include <syslog.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
openlog("fig3-7", LOG_PERROR | LOG_PID | LOG_NDELAY, LOG_USER);
syslog(LOG_NOTICE, "Hello Syslog!");
syslog(LOG_INFO, "Here's an informational message.");
syslog(LOG_WARNING, "Here's a warning.");
syslog(LOG_ERR, "Here's an error.");
syslog(LOG_DEBUG, "Here's some debugging information.\n");
for (int i = 0; i < 10000000; ++i)
{
syslog(LOG_DEBUG, "%i", i);
sleep(1);
}
closelog();
exit(EXIT_SUCCESS);
}
fig3-7[8726]: Hello Syslog!
fig3-7[8726]: Here's an informational message.
fig3-7[8726]: Here's a warning.
fig3-7[8726]: Here's an error.
fig3-7[8726]: Here's some debugging information.
fig3-7[8726]: 0
fig3-7[8726]: 1
fig3-7[8726]: 2
fig3-7[8726]: 3
fig3-7[8726]: 4
.
.
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment