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.

Logger_syslog.cxx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2015 TigerVNC
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- Logger_syslog.cxx - Logger instance for a syslog
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <syslog.h>
  25. #include <rfb/util.h>
  26. #include <rfb/Logger_syslog.h>
  27. #include <rfb/LogWriter.h>
  28. using namespace rfb;
  29. Logger_Syslog::Logger_Syslog(const char* loggerName)
  30. : Logger(loggerName)
  31. {
  32. openlog(0, LOG_CONS | LOG_PID, LOG_USER);
  33. }
  34. Logger_Syslog::~Logger_Syslog()
  35. {
  36. closelog();
  37. }
  38. void Logger_Syslog::write(int level, const char *logname, const char *message)
  39. {
  40. // Convert our priority level into syslog level
  41. int priority;
  42. if (level >= LogWriter::LEVEL_DEBUG) {
  43. priority = LOG_DEBUG;
  44. } else if (level >= LogWriter::LEVEL_INFO) {
  45. priority = LOG_INFO;
  46. } else if (level >= LogWriter::LEVEL_STATUS) {
  47. priority = LOG_NOTICE;
  48. } else {
  49. priority = LOG_ERR;
  50. }
  51. syslog(priority, "%s: %s", logname, message);
  52. }
  53. static Logger_Syslog logger("syslog");
  54. void rfb::initSyslogLogger() {
  55. logger.registerLogger();
  56. }