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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include <stdlib.h>
  20. #include <string.h>
  21. #include <syslog.h>
  22. #include <rfb/util.h>
  23. #include <rfb/Logger_syslog.h>
  24. #include <rfb/LogWriter.h>
  25. using namespace rfb;
  26. Logger_Syslog::Logger_Syslog(const char* loggerName)
  27. : Logger(loggerName)
  28. {
  29. openlog(0, LOG_CONS | LOG_PID, LOG_USER);
  30. }
  31. Logger_Syslog::~Logger_Syslog()
  32. {
  33. closelog();
  34. }
  35. void Logger_Syslog::write(int level, const char *logname, const char *message)
  36. {
  37. // Convert our priority level into syslog level
  38. int priority;
  39. if (level >= LogWriter::LEVEL_DEBUG) {
  40. priority = LOG_DEBUG;
  41. } else if (level >= LogWriter::LEVEL_INFO) {
  42. priority = LOG_INFO;
  43. } else if (level >= LogWriter::LEVEL_STATUS) {
  44. priority = LOG_NOTICE;
  45. } else {
  46. priority = LOG_ERR;
  47. }
  48. syslog(priority, "%s: %s", logname, message);
  49. }
  50. static Logger_Syslog logger("syslog");
  51. void rfb::initSyslogLogger() {
  52. logger.registerLogger();
  53. }