Comment servir des pintes de Guinness "over Internet" ;) Reprise/Fork d'un très ancien code d'un pilier de f.m.b.l : http://tnemeth.free.fr/projets/guinness-server.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printlog.c 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * printlog
  3. * architecture clients/serveur guinness
  4. * Thomas Nemeth / Arnaud Giersch -- le 23 aout 2001
  5. *
  6. */
  7. #include <stdio.h>
  8. #include <time.h>
  9. #ifdef SunOS
  10. #include <sys/varargs.h>
  11. #else
  12. #include <stdarg.h>
  13. #endif
  14. #include <string.h>
  15. #include "defines.h"
  16. #include "printlog.h"
  17. extern FILE *outerr;
  18. extern FILE *logfile;
  19. void printlog (log_level loglevel, const char *format, ...) {
  20. va_list ap;
  21. FILE *stream = logfile;
  22. time_t now;
  23. struct tm *today;
  24. char date_time[MAXSTRLEN];
  25. va_start (ap, format);
  26. switch (loglevel) {
  27. case LOG_NOTIFY:
  28. stream = logfile;
  29. break;
  30. case LOG_ERROR:
  31. stream = outerr;
  32. break;
  33. default:
  34. stream = outerr;
  35. break;
  36. }
  37. time (&now);
  38. today = localtime (&now);
  39. memset (date_time, 0, MAXSTRLEN);
  40. strftime (date_time, MAXSTRLEN - 1, "%a %d %b %Y %T", today);
  41. fprintf (stream, "guinnessd: %s - ", date_time);
  42. vfprintf (stream, format, ap);
  43. va_end (ap);
  44. }