diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/gitblit/GitBlitServer.java | 34 | ||||
-rw-r--r-- | src/main/java/log4j.properties | 4 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/GitBlitServer.java b/src/main/java/com/gitblit/GitBlitServer.java index 522fb579..1e51577a 100644 --- a/src/main/java/com/gitblit/GitBlitServer.java +++ b/src/main/java/com/gitblit/GitBlitServer.java @@ -20,6 +20,7 @@ import java.io.BufferedWriter; import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
@@ -33,8 +34,10 @@ import java.text.MessageFormat; import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Properties;
import java.util.Scanner;
+import org.apache.log4j.PropertyConfigurator;
import org.eclipse.jetty.ajp.Ajp13SocketConnector;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
@@ -179,6 +182,34 @@ public class GitBlitServer { settings = new FileSettings(params.settingsfile);
}
}
+
+ if (params.dailyLogFile) {
+ // Configure log4j for daily log file generation
+ InputStream is = null;
+ try {
+ is = getClass().getResourceAsStream("/log4j.properties");
+ Properties loggingProperties = new Properties();
+ loggingProperties.load(is);
+
+ loggingProperties.put("log4j.appender.R.File", new File(baseFolder, "logs/gitblit.log").getAbsolutePath());
+ loggingProperties.put("log4j.rootCategory", "INFO, R");
+
+ if (settings.getBoolean(Keys.web.debugMode, false)) {
+ loggingProperties.put("log4j.logger.com.gitblit", "DEBUG");
+ }
+
+ PropertyConfigurator.configure(loggingProperties);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
logger = LoggerFactory.getLogger(GitBlitServer.class);
logger.info(Constants.BORDER);
logger.info(" _____ _ _ _ _ _ _");
@@ -614,6 +645,9 @@ public class GitBlitServer { @Parameter(names = { "--tempFolder" }, description = "Folder for server to extract built-in webapp")
public String temp = FILESETTINGS.getString(Keys.server.tempFolder, "temp");
+ @Parameter(names = { "--dailyLogFile" }, description = "Log to a rolling daily log file INSTEAD of stdout.")
+ public Boolean dailyLogFile = false;
+
/*
* GIT Servlet Parameters
*/
diff --git a/src/main/java/log4j.properties b/src/main/java/log4j.properties index ea29bded..c6b5d8c3 100644 --- a/src/main/java/log4j.properties +++ b/src/main/java/log4j.properties @@ -49,9 +49,9 @@ log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%-5p] %m%n log4j.appender.R = org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File = logs/gitblit.log log4j.appender.R.Append = true -log4j.appender.R.DatePattern = '.'yyy-MM-dd +log4j.appender.R.DatePattern = '.'yyyy-MM-dd log4j.appender.R.layout = org.apache.log4j.PatternLayout -log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c-30{1} [%-5p] %m%n +log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%-5p] %m%n #------------------------------------------------------------------------------ # |