1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
|
/* $Id: pilmessages.c,v 1.1.1.1 2008-10-21 09:10:13 cizzo Exp $
*
* This file is part of the VIMOS pipeline library
* Copyright (C) 2000-2004 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* $Author: cizzo $
* $Date: 2008-10-21 09:10:13 $
* $Revision: 1.1.1.1 $
* $Name: not supported by cvs2svn $
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/*
#include <termio.h>
*/
#include <signal.h>
/*
#include <stropts.h>
*/
#include <time.h>
#include "pildate.h"
#include "pilmessages.h"
/*
* This is the max length for text lines that are written to the logfile.
* It is also the max length for text lines sent to the terminal, in case
* the window size cannot be determined by the appropriate call to ioctl().
*/
#define PIL_TERM_WIDTH (80)
static struct sigaction act, oact;
/**
* @defgroup pilMessages pilMessages
*
* The module @b pilMessages provides functions to display and
* logging messages from the DRS.
*/
/**@{*/
/* FIXME:
* The following private members might be organized in one (or more)
* structures, in case a complete description of the messaging system
* configuration is requested by the client.
*/
static PilMsgSeverity logMinLevel = PIL_MSG_OFF;
static PilMsgSeverity terminalMinLevel = PIL_MSG_ERROR;
static int timeTag = 0;
static int recipeTag = 1;
static int componentTag = 0;
static char recipeName[MAX_RECIPE_NAME] = "Undefined";
static char logfileName[MAX_LOGFILE_NAME] = ".logfile";
static FILE *logfilePointer = NULL;
static int pageWidth = PIL_TERM_WIDTH;
/*
* Enable this if you want split lines in log file:
*
* static int logWidth = PIL_TERM_WIDTH;
*/
static int indentStep = 2;
static int indentValue = 0;
static FILE *msgStdout;
static FILE *msgStderr;
static int outStream;
static int errStream;
/*
* Installable print handlers
*/
static PilPrintFunc pil_message_printer = NULL;
static PilPrintFunc pil_error_printer = NULL;
/*
* To save the default handlers at messaging startup, so that they
* can be restored when the system is shut down.
*/
static PilPrintFunc _pil_message_printer = NULL;
static PilPrintFunc _pil_error_printer = NULL;
static void
_pil_message_print(const char *message)
{
fputs(message, msgStdout);
fflush(msgStdout);
return;
}
static void
_pil_error_print(const char *message)
{
fputs(message, msgStderr);
fflush(msgStderr);
return;
}
static void
_pil_print(const char *format, ...)
{
va_list args;
char string[MAX_MESSAGE_LENGTH + 1];
PilPrintFunc printer;
if (format == NULL) {
return;
}
va_start(args, format);
#ifdef HAVE_VSNPRINTF
vsnprintf(string, (size_t) MAX_MESSAGE_LENGTH, format, args);
#else
vsprintf(string, format, args);
#endif
string[MAX_MESSAGE_LENGTH] = '\0';
printer = pil_message_printer;
if (printer != NULL) {
printer(string);
}
else {
fputs(string, stdout);
fflush(stdout);
}
return;
}
static void
_pil_printerr(const char *format, ...)
{
va_list args;
char string[MAX_MESSAGE_LENGTH + 1];
PilPrintFunc printer;
if (format == NULL) {
return;
}
va_start(args, format);
#ifdef HAVE_VSNPRINTF
vsnprintf(string, (size_t) MAX_MESSAGE_LENGTH, format, args);
#else
vsprintf(string, format, args);
#endif
string[MAX_MESSAGE_LENGTH] = '\0';
printer = pil_error_printer;
if (printer != NULL) {
printer(string);
}
else {
fputs(string, stderr);
fflush(stderr);
}
return;
}
/*
* @brief
* Signal handler for signal @c SIGWINCH
*
* @param i Dummy argument (not used!)
*
* @return Nothing.
*
* The function accomodates the output line width of the messaging
* subsystem to the new window size on arrival of the signal @c SIGWINCH.
*/
/*
static void pilMsgChangeWidth(int i)
{
struct winsize win;
i = 0;
if (ioctl(outStream, TIOCGWINSZ, &win) < 0 || win.ws_col < 1)
pageWidth = PIL_TERM_WIDTH;
else
pageWidth = win.ws_col;
}
*/
/*
* @brief
* Format and output message string.
*
* @param severity Severity level of the incoming message.
* @param functionName Name of the function generating the message.
* @param format Format string in the usual C convention.
* @param al Variable argument list associated to the format string.
*
* @return Nothing.
*
* This function is used internally to actually display/add the
* message to terminal and/or logfile. Messages with severity
* level equal to "warning" or greater would be sent to stderr,
* the other messages would go to stdout.
*
* If the severity level is lower than the levels set by
* @b pilMsgEnableTerminal() and @b pilMsgEnableLog(), then the message
* is not displayed.
*
* @see pilMsgEnableTerminal(), pilMsgEnableLog()
*/
static void pilMsgOut(PilMsgSeverity severity,
const char *functionName, char *format,
va_list al)
{
time_t seconds;
char messageText[MAX_MESSAGE_LENGTH];
char messageLog[MAX_MESSAGE_LENGTH];
char messageTerminal[MAX_MESSAGE_LENGTH];
/*
* Enable this if you want split lines in log file:
* int startLogLine;
*/
int startTerminalLine;
int i;
if (severity < terminalMinLevel && severity < logMinLevel) return;
if (severity == PIL_MSG_OFF) return;
seconds = time((time_t *)0);
#ifdef HAVE_VSNPRINTF
vsnprintf(messageText, (size_t) MAX_MESSAGE_LENGTH, format, al);
#else
vsprintf(messageText, format, al);
#endif
/*
* For safety, truncate the message to MAX_MESSAGE_LENGTH
*/
messageText[MAX_MESSAGE_LENGTH-1] = '\0';
/*
* Date and time. Note that time tag and severity field are not
* affected by indentation. Date and time are always present in
* logfile, optional in terminal output.
*/
strftime(messageLog, MAX_MESSAGE_LENGTH, "%H:%M:%S ", localtime(&seconds));
if (timeTag) {
strftime(messageTerminal,MAX_MESSAGE_LENGTH,"%H:%M:%S ",
localtime(&seconds));
}
else {
messageTerminal[0] = '\0';
}
/*
* Severity label
*/
if (severity == PIL_MSG_ERROR) {
strcat(messageLog, ERROR_STRING);
strcat(messageTerminal, ERROR_STRING);
}
else if (severity == PIL_MSG_WARNING) {
strcat(messageLog, WARNING_STRING);
strcat(messageTerminal, WARNING_STRING);
}
else if (severity == PIL_MSG_INFO) {
strcat(messageLog, INFO_STRING);
strcat(messageTerminal, INFO_STRING);
}
else if (severity == PIL_MSG_DEBUG) {
strcat(messageLog, DEBUG_STRING);
strcat(messageTerminal, DEBUG_STRING);
}
/*
* Recipe, function name, and message appended:
*/
if (recipeTag) {
strcat(messageTerminal, recipeName);
strcat(messageTerminal, ": ");
}
/*
* Enable this if you want split lines in log file:
*
* startLogLine = strlen(messageLog);
*/
startTerminalLine = strlen(messageTerminal);
if (componentTag) {
strcat(messageTerminal, functionName);
strcat(messageTerminal, "() ");
}
strcat(messageLog, functionName);
strcat(messageLog, "() ");
/*
* Message indentation
*/
for (i=0; i<indentValue; i++) {
strcat(messageLog, " ");
strcat(messageTerminal, " ");
}
strcat(messageLog, messageText);
strcat(messageTerminal, messageText);
if (severity >= logMinLevel) {
/*
* Enable this (and disable the next line) if you want split lines in log file:
*
* fprintf(logfilePointer, "%s\n", strsplit(messageLog, startLogLine,
* logWidth));
*/
fprintf(logfilePointer, "%s\n", messageLog);
}
if (severity >= terminalMinLevel) {
if (severity > PIL_MSG_WARNING) {
_pil_printerr("%s\n", strsplit(messageTerminal, startTerminalLine,
pageWidth));
}
else {
_pil_print("%s\n", strsplit(messageTerminal, startTerminalLine,
pageWidth));
}
}
}
/**
* @brief
* Initialize the messaging system
*
* @return @c EXIT_SUCCESS or @c EXIT_FAILURE
*
* Currently just the terminal width is determined (if possible),
* and the resized window signal handler is deployed.
*/
int pilMsgStart(void)
{
/*
struct winsize win;
*/
/*
* First duplicate stdout and stderr streams
*/
if (!(outStream = dup(fileno(stdout))))
return EXIT_FAILURE;
if (!(errStream = dup(fileno(stderr))))
return EXIT_FAILURE;
if (!(msgStdout = fdopen(outStream, "a")))
return EXIT_FAILURE;
if (!(msgStderr = fdopen(errStream, "a")))
return EXIT_FAILURE;
_pil_message_printer = pilMsgSetPrintHandler(_pil_message_print);
_pil_error_printer = pilMsgSetErrorHandler(_pil_error_print);
/*
* Get the terminal window size, and if successful deploy the handler
* for any image resizing at runtime.
*/
/*
if (ioctl(outStream, TIOCGWINSZ, &win) < 0 || win.ws_col < 1)
return EXIT_SUCCESS;
pageWidth = win.ws_col;
act.sa_handler = pilMsgChangeWidth;
sigemptyset(&act.sa_mask);
act.sa_flags = 0; * Probably more appropriate flags *
* initialization should be inserted here. *
act.sa_flags &= ~SA_SIGINFO; * Eliminates SA_SIGINFO from any setting *
* above. *
sigaction(SIGWINCH, &act, &oact);
*/
return EXIT_SUCCESS;
}
/**
* @brief
* Shutdown the messaging system
*
* @return @c EXIT_SUCCESS or @c EXIT_FAILURE
*
* The original SIGWINCH signal handler is restored.
*/
void pilMsgStop(void)
{
/*
if (act.sa_handler == pilMsgChangeWidth)
sigaction(SIGWINCH, &oact, NULL);
*/
fclose(msgStdout);
fclose(msgStderr);
pilMsgSetPrintHandler(_pil_message_printer);
pilMsgSetErrorHandler(_pil_error_printer);
return;
}
/**
* @brief
* Open and initialize the log file.
*
* @param severity Specification of the lowest severity level a message
* should have to be written to log file.
*
* @return @c EXIT_SUCCESS or @c EXIT_FAILURE
*
* The logfile name is the same as the recipe name, with
* a time tag and the extension .log appended. Tipically
* this function would be called at pipeline initialization,
* when a given recipe is run. Calling it again would
* close the previous logfile, and start a new one with
* the same name and a different time tag.
*/
int pilMsgEnableLog(PilMsgSeverity severity)
{
char *timeLabel;
if (logfilePointer) {
/*
* If a log file was already open, close it before initializing
* a new one.
*/
if (pilMsgCloseLog() == EXIT_FAILURE) {
return EXIT_FAILURE;
}
}
if (severity != PIL_MSG_OFF) {
logMinLevel = severity;
if ((logfilePointer = fopen(logfileName, "w")) == NULL) {
return EXIT_FAILURE;
}
/*
* Write log file header
*/
timeLabel = pilDateGetISO8601();
fprintf(logfilePointer, "\n");
fprintf(logfilePointer, "Start time : %s\n", timeLabel);
fprintf(logfilePointer, "Recipe name : %s\n", recipeName);
fprintf(logfilePointer, "Severity level : ");
switch(severity) {
case PIL_MSG_DEBUG : fprintf(logfilePointer, DEBUG_STRING); break;
case PIL_MSG_INFO : fprintf(logfilePointer, INFO_STRING); break;
case PIL_MSG_WARNING : fprintf(logfilePointer, WARNING_STRING); break;
case PIL_MSG_ERROR : fprintf(logfilePointer, ERROR_STRING); break;
default : ;
}
fprintf(logfilePointer, "\n\n");
}
return EXIT_SUCCESS;
}
/**
* @brief
* Close the current log file.
*
* @return @c EXIT_SUCCESS or @c EXIT_FAILURE.
*
* Typically this routine should be called at pipeline end.
*/
int pilMsgCloseLog(void)
{
if (logMinLevel != PIL_MSG_OFF) {
logMinLevel = PIL_MSG_OFF;
if (fclose(logfilePointer)) return EXIT_FAILURE;
logfilePointer = NULL;
}
return EXIT_SUCCESS;
}
/**
* @brief
* Get the logfile name.
*
* @return Logfile name
*
* Read access to internal static string.
*/
const char *pilMsgGetLogFile(void)
{
return logfileName;
}
/**
* @brief
* Enable output to terminal.
*
* @param severity Specification of the lowest severity level a message
* should have to be displayed to terminal.
*
* @return Nothing.
*
* Typically this function would be called at pipeline
* initialization, when a given recipe is run. Calling it
* again would have no effect but changing the severity
* level.
*/
void pilMsgEnableTerminal(PilMsgSeverity severity)
{
terminalMinLevel = severity;
if (severity == PIL_MSG_DEBUG) pilMsgEnableComponentTag();
}
/**
* @brief
* Get current log messaging level.
*
* @return Current severity level.
*
* Get current log messaging level.
*/
PilMsgSeverity pilMsgLogLevel(void)
{
return logMinLevel;
}
/**
* @brief
* Get current terminal messaging level.
*
* @return Current severity level.
*
* Get current terminal messaging level.
*/
PilMsgSeverity pilMsgTerminalLevel(void)
{
return terminalMinLevel;
}
/**
* @brief
* Enable a Time Tag to output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* time tag would be always added to a message written
* to the log file. If this routine is not called, the
* Time Tag is not used.
*/
void pilMsgEnableTimeTag(void)
{
timeTag = 1;
}
/**
* @brief
* Disable Time Tag to output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* time tag would be always added to a message written
* to the log file.
*/
void pilMsgDisableTimeTag(void)
{
timeTag = 0;
}
/**
* @brief
* Display Recipe Name before output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* recipe name would be always added to a message written
* to the log file.
*/
void pilMsgEnableRecipeTag(void)
{
recipeTag = 1;
}
/**
* @brief
* Disable display of Recipe Name before output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* recipe name would be always added to a message written
* to the log file. If this routine is not called, the
* recipe name is displayed before messages.
*/
void pilMsgDisableRecipeTag(void)
{
recipeTag = 0;
}
/**
* @brief
* Display Component Name (i.e., function) before output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* component name would be always added to a message written
* to the log file.
*/
void pilMsgEnableComponentTag(void)
{
componentTag = 1;
}
/**
* @brief
* Disable display of Component Name before output messages.
*
* @return Nothing.
*
* There is no analogous routine for the log file, as a
* recipe name would be always added to a message written
* to the log file. If this routine is not called, the
* recipe name is displayed before messages.
*/
void pilMsgDisableComponentTag(void)
{
componentTag = 0;
}
/**
* @brief
* Communicate the recipe name to the messaging system.
*
* @param name Any task identification string, typically the
* DRS recipe name..
*
* @return Nothing.
*
* This routine should be called at the recipe start,
* before a possible call to the function pilMsgEnableLog.
* The recipe name will be displayed at the beginning
* of any message to terminal, and in the header of
* the logfile.
*/
void pilMsgSetRecipeName(const char *name)
{
if (strlen(name) >= MAX_RECIPE_NAME) {
strncpy(recipeName, name, MAX_RECIPE_NAME);
recipeName[MAX_RECIPE_NAME-1] = '\0';
}
else {
strcpy(recipeName, name);
}
}
/**
* @brief
* Set the max width of the displayed text.
*
* @param width Max width of the displayed text.
*
* @return Nothing.
*
* If a message is longer than this width, it would be broken into
* shorter lines before display to terminal. This function is called
* by the messaging system every time the terminal window is resized,
* and the width is set equal to the new width of the terminal window.
*/
void pilMsgSetWidth(int width)
{
pageWidth = width;
}
/**
* @brief
* Set the indentation step.
*
* @param step Indentation step.
*
* @return Nothing.
*
* To maintain a constant message display style, this routine
* should be called at most once, and just at pipeline start.
* A message line might be moved leftward or rightward by a
* number of characters that is a multiple of the indentation
* step. Setting the indentation step to zero would eliminate
* messages indentation. If this function is not called, the
* indentation step is set to 2.
*/
void pilMsgSetIndentStep(int step)
{
indentStep = step;
}
/**
* @brief
* Set the indentation level.
*
* @param level Indentation level.
*
* @return Nothing.
*
* Any new message line will be indented by a number of character
* equal to the indentation level mutiplied by the indentation
* step.
*/
void pilMsgIndent(int level)
{
indentValue = level*indentStep;
}
/**
* @brief
* Increase messages indentation by one indentation step.
*
* @return Nothing.
*
* Calling this function is equivalent to increase the indentation
* level by 1.
*/
void pilMsgIndentMore(void)
{
indentValue += indentStep;
}
/**
* @brief
* Decrease messages indentation by one indentation step.
*
* @return Nothing.
*
* Calling this function is equivalent to decrease the indentation
* level by 1.
*/
void pilMsgIndentLess(void)
{
indentValue -= indentStep;
}
/**
* @brief
* Display an error message.
*
* @param functionName Name of the function generating the message.
* @param format Format string.
* @param ... Variable argument list associated to the format string.
*
* @return Nothing.
*
* Any new message line will be indented by a number of character
* equal to the indentation level mutiplied by the indentation
* step.
*
* The format string @em format should follow the usual C convention. New
* line characters should not be used, as the message would be split
* automatically according to the width specified with @ b pilMsgSetWidth().
* Inserting a new line character would enforce breaking a line of
* text even before the current row is filled, and should be indented
* only as the begin of a new paragraph of text.
*
* @see pilMsgSetWidth()
*/
void pilMsgError(const char *functionName, char *format, ...)
{
va_list al;
va_start(al, format);
pilMsgOut(PIL_MSG_ERROR, functionName, format, al);
va_end(al);
}
/**
* @brief
* Display a warning message.
*
* @param functionName Name of the function generating the message.
* @param format Format string.
* @param ... Variable argument list associated to the format string.
*
* @return Nothing.
*
* Any new message line will be indented by a number of character
* equal to the indentation level mutiplied by the indentation
* step.
*
* The format string @em format should follow the usual C convention. New
* line characters should not be used, as the message would be split
* automatically according to the width specified with @ b pilMsgSetWidth().
* Inserting a new line character would enforce breaking a line of
* text even before the current row is filled, and should be indented
* only as the begin of a new paragraph of text.
*
* @see pilMsgSetWidth()
*/
void pilMsgWarning(const char *functionName, char *format, ...)
{
va_list al;
va_start(al, format);
pilMsgOut(PIL_MSG_WARNING, functionName, format, al);
va_end(al);
}
/**
* @brief
* Display an informative message.
*
* @param functionName Name of the function generating the message.
* @param format Format string.
* @param ... Variable argument list associated to the format string.
*
* @return Nothing.
*
* Any new message line will be indented by a number of character
* equal to the indentation level mutiplied by the indentation
* step.
*
* The format string @em format should follow the usual C convention. New
* line characters should not be used, as the message would be split
* automatically according to the width specified with @ b pilMsgSetWidth().
* Inserting a new line character would enforce breaking a line of
* text even before the current row is filled, and should be indented
* only as the begin of a new paragraph of text.
*
* @see pilMsgSetWidth()
*/
void pilMsgInfo(const char *functionName, char *format, ...)
{
va_list al;
va_start(al, format);
pilMsgOut(PIL_MSG_INFO, functionName, format, al);
va_end(al);
}
/**
* @brief
* Display a debug message.
*
* @param functionName Name of the function generating the message.
* @param format Format string.
* @param ... Variable argument list associated to the format string.
*
* @return Nothing.
*
* Any new message line will be indented by a number of character
* equal to the indentation level mutiplied by the indentation
* step.
*
* The format string @em format should follow the usual C convention. New
* line characters should not be used, as the message would be split
* automatically according to the width specified with @ b pilMsgSetWidth().
* Inserting a new line character would enforce breaking a line of
* text even before the current row is filled, and should be indented
* only as the begin of a new paragraph of text.
*
* @see pilMsgSetWidth()
*/
void pilMsgDebug(const char *functionName, char *format, ...)
{
va_list al;
va_start(al, format);
pilMsgOut(PIL_MSG_DEBUG, functionName, format, al);
va_end(al);
}
/**
* @brief
* Set handler for message output.
*
* @param func New handler function.
*
* @return The previously set print handler.
*
* The function @em func is installed as the new message printing function.
* Any ordinary message is printed using this handler. The default print
* handler just outputs the message text to @c stdout.
*/
PilPrintFunc
pilMsgSetPrintHandler(PilPrintFunc func)
{
PilPrintFunc previous;
previous = pil_message_printer;
pil_message_printer = func;
return previous;
}
/**
* @brief
* Set handler for error message output.
*
* @param func New handler function.
*
* @return The previously set error message handler.
*
* The function @em func is installed as the new error message printing
* function. Any error message is printed using this handler. The default
* print handler just outputs the error message text to @c stderr.
*/
PilPrintFunc
pilMsgSetErrorHandler(PilPrintFunc func)
{
PilPrintFunc previous;
previous = pil_error_printer;
pil_error_printer = func;
return previous;
}
/**@}*/
|