Skip to content

Commit

Permalink
Add a basic syslog appender
Browse files Browse the repository at this point in the history
This commits allows photonvision to push logs to a remote syslog
server such as the one on the roboRIO. To enable this on the RIO
create a file in /etc/syslog-ng.d/ for example

@Version: 3.8

source s_net { tcp(ip(0.0.0.0) port(514) max-connections (5000)); udp(); };
destination d_syslog { file("/var/log/remotelogs/syslog"); };

log { source(s_net); destination(d_syslog); };

This is experimental
  • Loading branch information
willtoth committed Nov 5, 2024
1 parent 5d55d21 commit deeebdc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions photon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
// Zip
implementation 'org.zeroturnaround:zt-zip:1.14'

// Syslog
implementation "com.cloudbees:syslog-java-client:1.1.7"

implementation "org.xerial:sqlite-jdbc:3.41.0.0"
implementation("org.photonvision:rknn_jni-jni:$rknnVersion:linuxarm64") {
transitive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import org.photonvision.common.dataflow.DataChangeService;
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
import org.photonvision.common.util.TimedTaskManager;
import com.cloudbees.syslog.Facility;
import com.cloudbees.syslog.MessageFormat;
import com.cloudbees.syslog.Severity;
import com.cloudbees.syslog.sender.UdpSyslogMessageSender;

@SuppressWarnings("unused")
public class Logger {
Expand Down Expand Up @@ -106,6 +110,7 @@ public static String format(
static {
currentAppenders.add(new ConsoleLogAppender());
currentAppenders.add(uiLogAppender);
currentAppenders.add(new SyslogAppender("SomeCoprocessor", "172.22.11.2"));
addFileAppender(PathManager.getInstance().getLogPath());
cleanLogs(PathManager.getInstance().getLogsDir());
}
Expand Down Expand Up @@ -314,6 +319,50 @@ public void log(String message, LogLevel level) {
}
}

private static class SyslogAppender implements LogAppender {
private UdpSyslogMessageSender messageSender = new UdpSyslogMessageSender();

private Severity ConvertLogLevel(LogLevel level) {
switch (level) {
case DEBUG:
return Severity.DEBUG;
case ERROR:
return Severity.ERROR;
case INFO:
return Severity.INFORMATIONAL;
case TRACE:
return Severity.DEBUG;
case WARN:
return Severity.WARNING;
default:
return Severity.INFORMATIONAL;
}
}

public SyslogAppender(String hostname, String ip) {
this(hostname, ip, 514);
}

public SyslogAppender(String hostname, String ip, int port) {
messageSender.setDefaultMessageHostname(hostname);
messageSender.setDefaultAppName("photonvision");
messageSender.setDefaultFacility(Facility.USER);
messageSender.setDefaultSeverity(Severity.INFORMATIONAL);
messageSender.setSyslogServerHostname(ip);
messageSender.setSyslogServerPort(port);
messageSender.setMessageFormat(MessageFormat.RFC_5424);
}

@Override
public void log(String message, LogLevel level) {
messageSender.setDefaultSeverity(ConvertLogLevel(level));
try {
messageSender.sendMessage(message);
} catch (IOException e) {
}
}
}

private static class FileLogAppender implements LogAppender {
private OutputStream out;
private boolean wantsFlush;
Expand Down

0 comments on commit deeebdc

Please sign in to comment.