log_test.c revision ec5347e2c775f027573ce5648b910361aa926c01
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: log_test.c,v 1.25 2007/06/18 23:47:26 tbox Exp $ */
/* Principal Authors: DCL */
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/commandline.h>
#define SYSLOG_FILE "/var/log/daemon.log"
#define FILE_VERSIONS 10
char usage[] = "Usage: %s [-m] [-s syslog_logfile] [-r file_versions]\n";
if (result != ISC_R_SUCCESS) { \
}
int
const isc_logcategory_t *category;
const isc_logmodule_t *module;
progname++;
else
switch (ch) {
case 'm':
break;
case 's':
break;
case 'r':
if (file_versions < 0 &&
"%d (ISC_LOG_ROLLNEVER),\n\t"
"%d (ISC_LOG_ROLLINFINITE) "
"or > 0\n", progname,
exit(1);
}
break;
case '?':
exit(1);
}
}
if (argc > 0) {
exit(1);
}
"8 lines to stderr (first 4 numbered, #3 repeated)\n",
"2 lines to syslog\n",
"lines ending with exclamation marks are errors\n\n");
/*
* Test isc_log_categorybyname and isc_log_modulebyname.
*/
else
else
/*
* Create a file channel to test file opening, size limiting and
* version rolling.
*/
/*
* Create a dynamic debugging channel to a file descriptor.
*/
/*
* Test the usability of the four predefined logging channels.
*/
NULL));
/*
* Use the custom channels.
*/
/*
* Write to the internal default by testing both a category for which
* no channel has been specified and a category which was specified
* but not with the named module.
*/
stderr_line = 1;
ISC_LOG_CRITICAL, "%s (%d)",
"Unspecified category and unspecified module to stderr",
stderr_line++);
ISC_LOG_CRITICAL, "%s (%d)",
"Specified category and unspecified module to stderr",
stderr_line++);
/*
* Write to default_syslog, default_stderr and default_debug.
*/
ISC_LOG_WARNING, "%s (%d twice)",
"Using the predefined channels to syslog+stderr",
stderr_line++);
/*
* Write to predefined null channel.
*/
ISC_LOG_INFO, "This is to null and should not appear!");
/*
* Reset the internal default to use syslog instead of stderr,
* and test it.
*/
ISC_LOG_ERROR, "%s%s",
"This message to the redefined default category should ",
"be second in syslog");
/*
* Write to the file channel.
*/
/*
* If file_versions is 0 or ISC_LOG_ROLLINFINITE, write
* the "should not appear" and "should be in file" messages
* to ensure they get rolled.
*/
if (file_versions <= 0)
else
"This should be rolled over "
"and not appear!");
for (i = file_versions - 1; i >= 0; i--)
"should be in file %d/%d", i,
file_versions - 1);
"should be in base file");
} else {
for (i = 1; i <= file_versions; i++)
"This is message %d in the log file", i);
}
/*
* Write a debugging message to a category that has no
* debugging channels for the named module.
*/
ISC_LOG_DEBUG(1),
"This debug message should not appear!");
/*
* Write debugging messages to a dynamic debugging channel.
*/
ISC_LOG_CRITICAL, "This critical message should "
"not appear because the debug level is 0!");
"Dynamic debugging to stderr", stderr_line++);
ISC_LOG_DEBUG(5),
"This debug level is too high and should not appear!");
/*
* Test out the duplicate filtering using the debug_test channel.
*/
message = "This message should appear only once on stderr";
message = "This message should appear twice on stderr";
sleep(2);
/*
* Review where everything went.
* XXXDCL NT
*/
system("tail -2");
if (show_final_mem)
return (0);
}