mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 13:21:37 +02:00
Integrate slf4j simple logger and change some messages. Declare some exceptions in tests
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package uk.ac.ic.wlgitbridge.application;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.application.config.Config;
|
||||
import uk.ac.ic.wlgitbridge.application.exception.ConfigFileException;
|
||||
import uk.ac.ic.wlgitbridge.application.exception.ArgsException;
|
||||
import uk.ac.ic.wlgitbridge.application.exception.ConfigFileException;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
|
||||
import uk.ac.ic.wlgitbridge.server.GitBridgeServer;
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.util.Log;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
@@ -15,12 +15,14 @@ import java.io.IOException;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class that represents the application. Parses arguments and gives them to the server, or dies with a usage message.
|
||||
* Class that represents the application. Parses arguments and gives them to the
|
||||
* server, or dies with a usage message.
|
||||
*/
|
||||
public class GitBridgeApp implements Runnable {
|
||||
|
||||
public static final int EXIT_CODE_FAILED = 1;
|
||||
private static final String USAGE_MESSAGE = "usage: writelatex-git-bridge config_file";
|
||||
private static final String USAGE_MESSAGE =
|
||||
"usage: writelatex-git-bridge config_file";
|
||||
|
||||
private String configFilePath;
|
||||
private Config config;
|
||||
@@ -34,28 +36,39 @@ public class GitBridgeApp implements Runnable {
|
||||
try {
|
||||
parseArguments(args);
|
||||
loadConfigFile();
|
||||
Log.info("Config file loaded");
|
||||
} catch (ArgsException e) {
|
||||
printUsage();
|
||||
System.exit(EXIT_CODE_FAILED);
|
||||
} catch (ConfigFileException e) {
|
||||
System.err.println("The property for " + e.getMissingMember() + " is invalid. Check your config file.");
|
||||
Log.error(
|
||||
"The property for " +
|
||||
e.getMissingMember() +
|
||||
" is invalid. Check your config file."
|
||||
);
|
||||
System.exit(EXIT_CODE_FAILED);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Invalid config file. Check the file path.");
|
||||
Log.error("Invalid config file. Check the file path.");
|
||||
System.exit(EXIT_CODE_FAILED);
|
||||
}
|
||||
try {
|
||||
server = new GitBridgeServer(config);
|
||||
} catch (ServletException e) {
|
||||
Util.printStackTrace(e);
|
||||
Log.error(
|
||||
"Servlet exception when instantiating GitBridgeServer",
|
||||
e
|
||||
);
|
||||
} catch (InvalidRootDirectoryPathException e) {
|
||||
System.out.println("Invalid root git directory path. Check your config file.");
|
||||
Log.error(
|
||||
"Invalid root git directory path. Check your config file."
|
||||
);
|
||||
System.exit(EXIT_CODE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the server with the port number and root directory path given in the command-line arguments.
|
||||
* Starts the server with the port number and root directory path given in
|
||||
* the command-line arguments.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -88,7 +101,7 @@ public class GitBridgeApp implements Runnable {
|
||||
}
|
||||
|
||||
private void printUsage() {
|
||||
System.out.println(USAGE_MESSAGE);
|
||||
System.err.println(USAGE_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.ac.ic.wlgitbridge.data;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
import uk.ac.ic.wlgitbridge.util.Log;
|
||||
|
||||
/**
|
||||
* Created by Winston on 21/02/15.
|
||||
@@ -16,16 +16,15 @@ public class ShutdownHook extends Thread implements LockAllWaiter {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sout("Shutdown received.");
|
||||
Log.info("Shutdown received.");
|
||||
projectLock.lockAll();
|
||||
Util.sout("No projects to wait for.");
|
||||
Util.sout("Bye");
|
||||
Util.sout();
|
||||
Log.info("No projects to wait for.");
|
||||
Log.info("Bye");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void threadsRemaining(int threads) {
|
||||
Util.sout("Waiting for " + threads + " projects...");
|
||||
Log.info("Waiting for " + threads + " projects...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import uk.ac.ic.wlgitbridge.application.config.Config;
|
||||
import uk.ac.ic.wlgitbridge.application.jetty.NullLogger;
|
||||
import uk.ac.ic.wlgitbridge.bridge.BridgeAPI;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
|
||||
import uk.ac.ic.wlgitbridge.git.servlet.WLGitServlet;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.SnapshotAPIRequest;
|
||||
import uk.ac.ic.wlgitbridge.util.Log;
|
||||
import uk.ac.ic.wlgitbridge.util.Util;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
@@ -41,7 +41,7 @@ public class GitBridgeServer {
|
||||
private String apiBaseURL;
|
||||
|
||||
public GitBridgeServer(Config config) throws ServletException, InvalidRootDirectoryPathException {
|
||||
Log.setLog(new NullLogger());
|
||||
org.eclipse.jetty.util.log.Log.setLog(new NullLogger());
|
||||
this.port = config.getPort();
|
||||
this.rootGitDirectoryPath = config.getRootGitDirectory();
|
||||
bridgeAPI = new BridgeAPI(rootGitDirectoryPath);
|
||||
@@ -61,15 +61,15 @@ public class GitBridgeServer {
|
||||
public void start() {
|
||||
try {
|
||||
jettyServer.start();
|
||||
Util.sout(Util.getServiceName() + "-Git Bridge server started");
|
||||
Util.sout("Listening on port: " + port);
|
||||
Util.sout("Bridged to: " + apiBaseURL);
|
||||
Util.sout("Postback base URL: " + Util.getPostbackURL());
|
||||
Util.sout("Root git directory path: " + rootGitDirectoryPath);
|
||||
Log.info(Util.getServiceName() + "-Git Bridge server started");
|
||||
Log.info("Listening on port: " + port);
|
||||
Log.info("Bridged to: " + apiBaseURL);
|
||||
Log.info("Postback base URL: " + Util.getPostbackURL());
|
||||
Log.info("Root git directory path: " + rootGitDirectoryPath);
|
||||
} catch (BindException e) {
|
||||
Util.printStackTrace(e);
|
||||
Log.error("Failed to bind Jetty", e);
|
||||
} catch (Exception e) {
|
||||
Util.printStackTrace(e);
|
||||
Log.error("Failed to start Jetty", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class GitBridgeServer {
|
||||
try {
|
||||
jettyServer.stop();
|
||||
} catch (Exception e) {
|
||||
Util.printStackTrace(e);
|
||||
Log.error("Failed to stop Jetty", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package uk.ac.ic.wlgitbridge.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.impl.SimpleLogger;
|
||||
import uk.ac.ic.wlgitbridge.application.GitBridgeApp;
|
||||
|
||||
/**
|
||||
* Created by winston on 19/01/2016.
|
||||
*/
|
||||
public class Log {
|
||||
|
||||
static {
|
||||
System.setProperty(SimpleLogger.SHOW_DATE_TIME_KEY, "true");
|
||||
System.setProperty(SimpleLogger.DATE_TIME_FORMAT_KEY, "yyyy-MM-dd HH:mm:ss:SSS Z");
|
||||
}
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GitBridgeApp.class);
|
||||
|
||||
public static void trace(String msg) {
|
||||
logger.trace(msg);
|
||||
}
|
||||
|
||||
public static void trace(String msg, Throwable t) {
|
||||
logger.trace(msg, t);
|
||||
}
|
||||
|
||||
public static void debug(String msg) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
public static void debug(String msg, Throwable t) {
|
||||
logger.debug(msg, t);
|
||||
}
|
||||
|
||||
public static void info(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
public static void info(String format, Object arg) {
|
||||
logger.info(format, arg);
|
||||
}
|
||||
|
||||
public static void info(String format, Object arg1, Object arg2) {
|
||||
logger.info(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public static void info(String format, Object... args) {
|
||||
logger.info(format, args);
|
||||
}
|
||||
|
||||
public static void info(String msg, Throwable t) {
|
||||
logger.info(msg, t);
|
||||
}
|
||||
|
||||
public static void warn(String msg) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
|
||||
public static void warn(String msg, Object arg) {
|
||||
logger.warn(msg, arg);
|
||||
}
|
||||
|
||||
public static void warn(String msg, Object arg1, Object arg2) {
|
||||
logger.warn(msg, arg1, arg2);
|
||||
}
|
||||
|
||||
public static void warn(String msg, Object... args) {
|
||||
logger.warn(msg, args);
|
||||
}
|
||||
|
||||
public static void warn(String msg, Throwable t) {
|
||||
logger.warn(msg, t);
|
||||
}
|
||||
|
||||
public static void error(String msg) {
|
||||
logger.error(msg);
|
||||
}
|
||||
|
||||
public static void error(String msg, Throwable t) {
|
||||
logger.error(msg, t);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user