Skip to content

Commit 20fcfc3

Browse files
committed
daemon: Add RollingFileAppender to the Daemon
1 parent 5c8af7b commit 20fcfc3

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

opencga-app/app/bin/opencga-start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PRGDIR=`dirname "$0"`
44
BASEDIR=`cd "$PRGDIR/.." >/dev/null; pwd`
55
OPENCGA_DAEMON_BIN=$BASEDIR'/bin/opencga-daemon.sh'
66

7-
mkdir -p $BASEDIR/log
7+
mkdir -p $BASEDIR/logs
88
export OPENCGA_HOME=$BASEDIR
99

10-
exec $OPENCGA_DAEMON_BIN $@ &>> $BASEDIR/logs/daemon.log &
10+
exec $OPENCGA_DAEMON_BIN $@ &>> /dev/null &

opencga-app/app/bin/opencga-stop.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ PRGDIR=`dirname "$0"`
44
BASEDIR=`cd "$PRGDIR/.." >/dev/null; pwd`
55
daemon_port=`grep "OPENCGA.APP.DAEMON.PORT" ${BASEDIR}/conf/daemon.properties | cut -d "=" -f2`
66

7-
curl "http://localhost:${daemon_port}/opencga/rest/admin/stop"
7+
curl "http://localhost:${daemon_port}/opencga/rest/admin/stop"
8+
9+
echo ""

opencga-app/src/main/java/org/opencb/opencga/app/daemon/OpenCGADaemon.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//import net.dpml.http.ServletContextHandler;
2828

2929

30+
import org.apache.log4j.*;
3031
import org.opencb.opencga.core.common.Config;
3132

3233

@@ -58,6 +59,11 @@ public static void main(String args[]) throws IOException {
5859

5960
OptionParser.GeneralOptions opts = optionParser.getGeneralOptions();
6061

62+
if (opts.help) {
63+
System.out.println(optionParser.usage());
64+
return;
65+
}
66+
6167
//Get properties
6268
String propertyAppHome = System.getProperty("app.home");
6369
if (propertyAppHome != null) {
@@ -70,7 +76,11 @@ public static void main(String args[]) throws IOException {
7076
opencgaHome = Paths.get("opencga-app", "build").toString(); //If it has not been run from the shell script (debug)
7177
}
7278
}
79+
7380
Config.setGcsaHome(opencgaHome);
81+
82+
setLogLevel(opts.logLevel);
83+
7484
File configFile;
7585
if(opts.conf.isEmpty()) {
7686
configFile = Paths.get(opencgaHome, "conf", "daemon.properties").toFile();
@@ -110,5 +120,34 @@ public static DaemonLoop getDaemon() {
110120
}
111121

112122

123+
public static void setLogLevel(String logLevel) {
124+
125+
String logFile = null;
126+
org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
127+
try {
128+
java.nio.file.Path logs = Paths.get(Config.getOpenCGAHome(), "logs");
129+
//Files.createDirectory(logs);
130+
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %m%n");
131+
logFile = logs.resolve("daemon.log").toString();
132+
RollingFileAppender rollingFileAppender = new RollingFileAppender(layout, logFile, true);
133+
rollingFileAppender.setThreshold(Level.DEBUG);
134+
rollingFileAppender.setMaxFileSize("100MB");
135+
rollingFileAppender.setMaxBackupIndex(50);
136+
rootLogger.setLevel(Level.TRACE);
137+
rootLogger.addAppender(rollingFileAppender);
138+
} catch (IOException e) {
139+
e.printStackTrace();
140+
}
141+
142+
// This small hack allow to configure the appropriate Logger level from the command line, this is done
143+
// by setting the DEFAULT_LOG_LEVEL_KEY before the logger object is created.
144+
// System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, logLevel);
145+
146+
ConsoleAppender stderr = (ConsoleAppender) rootLogger.getAppender("stderr");
147+
stderr.setThreshold(Level.toLevel(logLevel));
148+
149+
logger = LoggerFactory.getLogger(OpenCGADaemon.class);
150+
}
151+
113152
}
114153

opencga-app/src/main/java/org/opencb/opencga/app/daemon/OptionParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class GeneralOptions {
6969
boolean verbose = false;
7070

7171
@Parameter(names = {"-L", "--log-level"}, description = "This parameter set the level of the logging", required = false, arity = 1)
72-
int logLevel;
72+
String logLevel = "info";
7373

7474
@DynamicParameter(names = "-D", description = "Dynamic parameters go here", hidden = true)
7575
Map<String, String> params = new HashMap<String, String>();

0 commit comments

Comments
 (0)