callback_log.c 551 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * callback_log.c
  3. *
  4. * Callback hook to log users's commands
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <syslog.h>
  9. #include "internal.h"
  10. #define SYSLOG_IDENT "klish"
  11. #define SYSLOG_FACILITY LOG_LOCAL0
  12. /*--------------------------------------------------------- */
  13. int clish_log_callback(clish_context_t *context, const char *line,
  14. int retcode)
  15. {
  16. /* Initialization */
  17. if (!line) {
  18. openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY);
  19. return 0;
  20. }
  21. /* Log the given line */
  22. syslog(LOG_INFO, "%s : %d", line, retcode);
  23. return 0;
  24. }