The Open Source Swiss Army Knife

/code/c/unix_c/
/code/c/unix_c/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c 
Permalink: mask_log.c
Title: demonstrate openlog() and family
article options : please login   |  raw source view  

/*
 * Listing 13.8
 * mask_log.c - demonstrate openlog() and family
 */
#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(void)
{
	int ret;

	openlog("mask_log", LOG_PID, LOG_USER);
	syslog(LOG_INFO, "This message courtesy of UID #%d\n", getuid());
	syslog(LOG_NOTICE, "Hopefully, you see this\n");

	/* Don't want to see DEBUG and INFO messages */
	ret = setlogmask(LOG_UPTO(LOG_NOTICE));
	syslog(LOG_INFO, "You should not be seeing this\n");
	syslog(LOG_DEBUG, "I hope you don't see this\n");
	syslog(LOG_NOTICE, "This should still appear\n");

	closelog();
	exit(EXIT_SUCCESS);
}

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top