Remove the outpuf file option to simplify. There are better options, eg. pipe output to the Apache rotatelogs tool.
This commit is contained in:
parent
0a887bc644
commit
039468ae42
|
@ -17,7 +17,7 @@ pipelines:
|
||||||
- gradle
|
- gradle
|
||||||
name: Build and Release
|
name: Build and Release
|
||||||
script:
|
script:
|
||||||
- ./gradlew clean build shadowJar buildRpm buildDeb
|
- ./gradlew clean versionFile build shadowJar buildRpm buildDeb
|
||||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*-all.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*-all.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.rpm ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.rpm ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.deb ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.deb ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
@Command(name = "syslogd",
|
@Command(name = "syslogd",
|
||||||
|
@ -30,25 +30,22 @@ import java.util.concurrent.Callable;
|
||||||
public class SyslogServer implements Callable<Integer>, LogListener {
|
public class SyslogServer implements Callable<Integer>, LogListener {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(SyslogServer.class);
|
private final static Logger log = LoggerFactory.getLogger(SyslogServer.class);
|
||||||
private BufferedWriter bw;
|
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-p", "--port"}, description = "Listening port [default: 514]")
|
@CommandLine.Option(names = {"-p", "--port"}, description = "Listening port [default: 514].")
|
||||||
private int port = 514;
|
private int port = 514;
|
||||||
|
|
||||||
@CommandLine.Option(names = "--no-udp", negatable = true, description = "Listen on UDP [default: true]")
|
@CommandLine.Option(names = "--no-udp", negatable = true, description = "Listen on UDP [default: true].")
|
||||||
boolean udpServer = true;
|
boolean udpServer = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = "--no-tcp", negatable = true, description = "Listen on TCP [default: true]")
|
@CommandLine.Option(names = "--no-tcp", negatable = true, description = "Listen on TCP [default: true].")
|
||||||
boolean tcpServer = true;
|
boolean tcpServer = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = "--rfc5424", negatable = false, description = "Parse RFC5424 messages [default: RFC3164]")
|
@CommandLine.Option(names = "--no-ansi", negatable = true, description = "Output ANSI colors [default: true].")
|
||||||
boolean rfc5424 = false;
|
|
||||||
|
|
||||||
@CommandLine.Option(names = "--no-ansi", negatable = true, description = "Output ANSI colors [default: true]")
|
|
||||||
boolean ansiOutput = true;
|
boolean ansiOutput = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-f", "--file"}, description = "Write output to file [default: STDOUT]")
|
@CommandLine.Option(names = "--rfc5424", description = "Parse RFC-5424 messages [default: RFC-3164].")
|
||||||
File outputFile;
|
boolean rfc5424 = false;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
int exitCode = new CommandLine(new SyslogServer()).execute(args);
|
int exitCode = new CommandLine(new SyslogServer()).execute(args);
|
||||||
|
@ -57,16 +54,7 @@ public class SyslogServer implements Callable<Integer>, LogListener {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer call() throws Exception {
|
public Integer call() throws IOException {
|
||||||
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
OutputStreamWriter w;
|
|
||||||
|
|
||||||
if(outputFile != null) {
|
|
||||||
fos = new FileOutputStream(outputFile);
|
|
||||||
w = new OutputStreamWriter(fos, "UTF-8");
|
|
||||||
bw = new BufferedWriter(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(udpServer) {
|
if(udpServer) {
|
||||||
UdpServer udpServer = new UdpServer(port);
|
UdpServer udpServer = new UdpServer(port);
|
||||||
|
@ -80,11 +68,6 @@ public class SyslogServer implements Callable<Integer>, LogListener {
|
||||||
tcpServer.start();
|
tcpServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(outputFile != null) {
|
|
||||||
bw.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,32 +89,6 @@ public class SyslogServer implements Callable<Integer>, LogListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(msg != null) {
|
if(msg != null) {
|
||||||
if(bw != null) {
|
|
||||||
writeToFile(msg);
|
|
||||||
} else {
|
|
||||||
writeToStdout(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void writeToFile(SyslogMessage msg) {
|
|
||||||
try {
|
|
||||||
if(ansiOutput) {
|
|
||||||
bw.append(msg.toAnsiString());
|
|
||||||
} else {
|
|
||||||
bw.append(msg.toString());
|
|
||||||
}
|
|
||||||
bw.newLine();
|
|
||||||
bw.flush();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("file error", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void writeToStdout(SyslogMessage msg) {
|
|
||||||
if(ansiOutput) {
|
if(ansiOutput) {
|
||||||
System.out.println(msg.toAnsiString());
|
System.out.println(msg.toAnsiString());
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,3 +97,5 @@ public class SyslogServer implements Callable<Integer>, LogListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue