From aa61fc86db4f5ebf645ecf69c6f5ec36f2973e5a Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 21 Feb 2014 11:14:47 -0500 Subject: [PATCH] Add GO launch parameter to specify daily, rolling log file generation --- releases.moxie | 3 +- src/main/java/com/gitblit/GitBlitServer.java | 34 ++++++++++++++++++++ src/main/java/log4j.properties | 4 +-- src/site/setup_go.mkd | 5 +-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/releases.moxie b/releases.moxie index 4fa313a7..0aa35efa 100644 --- a/releases.moxie +++ b/releases.moxie @@ -60,7 +60,8 @@ r20: { - Added raw links to the commit, commitdiff, and compare pages (issue-319) - Support intradocument linking in Markdown content using [[WikiLinks]] syntax (issue-324) - Support Markdown image links relative to the repository root (issue-324) - - Added filesystem write permission check (issue-345) + - Added filesystem write permission check (issue-345) + - Added GO launch parameter for redirecting logging to a rolling, daily log file (issue-348) - Support rendering confluence, mediawiki, textile, tracwiki, and twiki markup documents - Added setting to globally disable anonymous pushes in the receive pack - Added a normalized diffstat display to the commit, commitdiff, and compare pages 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 #------------------------------------------------------------------------------ # diff --git a/src/site/setup_go.mkd b/src/site/setup_go.mkd index 5d422fad..2e8f864a 100644 --- a/src/site/setup_go.mkd +++ b/src/site/setup_go.mkd @@ -124,6 +124,7 @@ Command-Line parameters override the values in `gitblit.properties` at runtime. --alias Alias in keystore of SSL cert to use for https serving --storePassword Password for SSL (https) keystore. --shutdownPort Port for Shutdown Monitor to listen on. (port <= 0 will disable this monitor) + --dailyLogFile Redirect logging to a rolling, daily log file instead of stdout --tempFolder Folder for server to extract built-in webapp **Example** @@ -135,6 +136,6 @@ Command-Line parameters override the values in `gitblit.properties` at runtime. You can override Gitblit GO's default Log4j configuration with a command-line parameter to the JVM. java -Dlog4j.configuration=file:///home/james/log4j.properties -jar gitblit.jar - -For reference, here is [Gitblit's default Log4j configuration](https://github.com/gitblit/gitblit/blob/master/src/log4j.properties). It includes some file appenders that are disabled by default. + +You can not use override the default log4j configuration *AND* specify the `--dailyLogFile` parameter. For reference, here is [Gitblit's default Log4j configuration](https://github.com/gitblit/gitblit/blob/master/src/log4j.properties). It includes some file appenders that are disabled by default. -- 2.39.5