fix: import path should be github.com/ooni/probe-cli/v3 (#200)
See https://github.com/ooni/probe/issues/1335#issuecomment-771499511
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#ifndef _WIN32
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
void ooniprobe_openlog(void) {
|
||||
#ifndef _WIN32
|
||||
(void)openlog("ooniprobe", LOG_PID, LOG_USER);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ooniprobe_log_debug(const char *message) {
|
||||
#ifndef _WIN32
|
||||
(void)syslog(LOG_DEBUG, "%s", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ooniprobe_log_info(const char *message) {
|
||||
#ifndef _WIN32
|
||||
(void)syslog(LOG_INFO, "%s", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ooniprobe_log_warning(const char *message) {
|
||||
#ifndef _WIN32
|
||||
(void)syslog(LOG_WARNING, "%s", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ooniprobe_log_err(const char *message) {
|
||||
#ifndef _WIN32
|
||||
(void)syslog(LOG_ERR, "%s", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ooniprobe_log_crit(const char *message) {
|
||||
#ifndef _WIN32
|
||||
(void)syslog(LOG_CRIT, "%s", message);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Package syslog contains a syslog handler.
|
||||
//
|
||||
// We use this handler on macOS systems to log messages
|
||||
// when ooniprobe is running in the background.
|
||||
package syslog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/apex/log"
|
||||
)
|
||||
|
||||
/*
|
||||
#include<stdlib.h>
|
||||
|
||||
void ooniprobe_openlog(void);
|
||||
void ooniprobe_log_debug(const char *message);
|
||||
void ooniprobe_log_info(const char *message);
|
||||
void ooniprobe_log_warning(const char *message);
|
||||
void ooniprobe_log_err(const char *message);
|
||||
void ooniprobe_log_crit(const char *message);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Default is the handler that emits logs with syslog
|
||||
var Default log.Handler = newhandler()
|
||||
|
||||
type handler struct{}
|
||||
|
||||
func newhandler() handler {
|
||||
C.ooniprobe_openlog()
|
||||
return handler{}
|
||||
}
|
||||
|
||||
func (h handler) HandleLog(e *log.Entry) error {
|
||||
message := fmt.Sprintf("%s %+v", e.Message, e.Fields)
|
||||
cstr := C.CString(message)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
switch e.Level {
|
||||
case log.DebugLevel:
|
||||
C.ooniprobe_log_debug(cstr)
|
||||
case log.InfoLevel:
|
||||
C.ooniprobe_log_info(cstr)
|
||||
case log.WarnLevel:
|
||||
C.ooniprobe_log_warning(cstr)
|
||||
case log.ErrorLevel:
|
||||
C.ooniprobe_log_err(cstr)
|
||||
default:
|
||||
C.ooniprobe_log_crit(cstr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user