Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix again [#99]

  • Loading branch information...
commit 30060f130e1369821deadcf99f7cd7109041c29a 1 parent 5ef2b4c
@guillaumebort guillaumebort authored
View
45 framework/src/play/Logger.java
@@ -27,27 +27,22 @@
* Will force use of java.util.logging (default to try log4j first).
*/
public static boolean forceJuli = false;
-
/**
* Will redirect all log from java.util.logging to log4j.
*/
public static boolean redirectJuli = false;
-
/**
* Will record and display the caller method.
*/
public static boolean recordCaller = false;
-
/**
* The application logger (play).
*/
public static org.apache.log4j.Logger log4j;
-
/**
* When using java.util.logging.
*/
public static java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
-
/**
* true if logger is configured manually (log4j-config file supplied by application)
*/
@@ -69,8 +64,11 @@ public static void init() {
PropertyConfigurator.configure(shutUp);
} else if (Logger.log4j == null) {
- //we're configuring the Logger manually.
- configuredManually = true;
+ // The log4j configuration file is outside of the framework,
+ // so it's probably a custom configuration file
+ if(log4jConf.getFile().indexOf(Play.frameworkPath.getAbsolutePath()) == -1) {
+ configuredManually = true;
+ }
PropertyConfigurator.configure(log4jConf);
Logger.log4j = org.apache.log4j.Logger.getLogger("play");
@@ -142,11 +140,10 @@ public static void setUp(String level) {
return juliLevel;
}
-
/**
* @return true if log4j.debug / jul.fine logging is enabled
*/
- public static boolean isDebugEnabled(){
+ public static boolean isDebugEnabled() {
if (forceJuli || log4j == null) {
return juli.isLoggable(java.util.logging.Level.FINE);
} else {
@@ -159,23 +156,22 @@ public static boolean isDebugEnabled(){
* @param level string representation of Logging-levels as used in log4j
* @return true if specified logging-level is enabled
*/
- public static boolean isEnabledFor( String level ){
+ public static boolean isEnabledFor(String level) {
//go from level-string to log4j-level-object
org.apache.log4j.Level log4jLevel = org.apache.log4j.Level.toLevel(level);
if (forceJuli || log4j == null) {
//must translate from log4j-level to jul-level
- java.util.logging.Level julLevel = toJuliLevel( log4jLevel.toString() );
+ java.util.logging.Level julLevel = toJuliLevel(log4jLevel.toString());
//check level against jul
- return juli.isLoggable( julLevel );
+ return juli.isLoggable(julLevel);
} else {
//check level against log4j
- return log4j.isEnabledFor( log4jLevel );
+ return log4j.isEnabledFor(log4jLevel);
}
}
-
/**
* Log with TRACE level
* @param message The message pattern
@@ -486,10 +482,10 @@ public static void fatal(Throwable e, String message, Object... args) {
}
}
}
-
+
/**
* If e is a PlayException -> a very clean report
- */
+ */
static boolean niceThrowable(org.apache.log4j.Level level, Throwable e, String message, Object... args) {
if (e instanceof Exception) {
@@ -510,8 +506,8 @@ static boolean niceThrowable(org.apache.log4j.Level level, Throwable e, String m
cleanTrace.add(new StackTraceElement("Invocation", "Job", "Play!", -1));
break;
}
- if(se.getClassName().startsWith("play.server.PlayHandler") && se.getMethodName().equals("messageReceived")) {
- cleanTrace.add(new StackTraceElement("Invocation", "Message Received", "Play!", -1));
+ if (se.getClassName().startsWith("play.server.PlayHandler") && se.getMethodName().equals("messageReceived")) {
+ cleanTrace.add(new StackTraceElement("Invocation", "Message Received", "Play!", -1));
break;
}
if (se.getClassName().startsWith("sun.reflect.")) {
@@ -539,9 +535,9 @@ static boolean niceThrowable(org.apache.log4j.Level level, Throwable e, String m
}
StringWriter sw = new StringWriter();
-
+
// Better format for Play exceptions
- if(e instanceof PlayException) {
+ if (e instanceof PlayException) {
PlayException playException = (PlayException) e;
PrintWriter errorOut = new PrintWriter(sw);
errorOut.println("");
@@ -636,10 +632,10 @@ private String toLog4jMessage(LogRecord record) {
Object parameters[] = record.getParameters();
if (parameters != null && parameters.length != 0) {
// Check for the first few parameters ?
- if (message.indexOf("{0}") >= 0 ||
- message.indexOf("{1}") >= 0 ||
- message.indexOf("{2}") >= 0 ||
- message.indexOf("{3}") >= 0) {
+ if (message.indexOf("{0}") >= 0
+ || message.indexOf("{1}") >= 0
+ || message.indexOf("{2}") >= 0
+ || message.indexOf("{3}") >= 0) {
message = MessageFormat.format(message, parameters);
}
}
@@ -672,4 +668,5 @@ public void close() {
// nothing to do
}
}
+
}
View
5 framework/src/play/server/PlayHandler.java
@@ -169,7 +169,9 @@ public boolean init() {
Request.current.set(request);
Response.current.set(response);
try {
- super.init();
+ if (Play.mode == Play.Mode.DEV) {
+ Router.detectChanges(Play.ctxPath);
+ }
if (Play.mode == Play.Mode.PROD && staticPathsCache.containsKey(request.path)) {
RenderStatic rs = null;
synchronized (staticPathsCache) {
@@ -180,6 +182,7 @@ public boolean init() {
return false;
}
Router.routeOnlyStatic(request);
+ super.init();
} catch (NotFound nf) {
serve404(nf, ctx, request, nettyRequest);
Logger.trace("init: end false");
View
67 framework/src/play/utils/ANSIConsoleAppender.java
@@ -0,0 +1,67 @@
+package play.utils;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Priority;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * Colour-coded console appender for Log4J.
+ */
+public class ANSIConsoleAppender extends ConsoleAppender {
+
+ static final int NORMAL = 0;
+ static final int BRIGHT = 1;
+ static final int FOREGROUND_BLACK = 30;
+ static final int FOREGROUND_RED = 31;
+ static final int FOREGROUND_GREEN = 32;
+ static final int FOREGROUND_YELLOW = 33;
+ static final int FOREGROUND_BLUE = 34;
+ static final int FOREGROUND_MAGENTA = 35;
+ static final int FOREGROUND_CYAN = 36;
+ static final int FOREGROUND_WHITE = 37;
+ static final String PREFIX = "\u001b[";
+ static final String SUFFIX = "m";
+ static final char SEPARATOR = ';';
+ static final String END_COLOUR = PREFIX + SUFFIX;
+ static final String FATAL_COLOUR = PREFIX + BRIGHT + SEPARATOR + FOREGROUND_RED + SUFFIX;
+ static final String ERROR_COLOUR = PREFIX + NORMAL + SEPARATOR + FOREGROUND_RED + SUFFIX;
+ static final String WARN_COLOUR = PREFIX + NORMAL + SEPARATOR + FOREGROUND_YELLOW + SUFFIX;
+ static final String INFO_COLOUR = PREFIX + SUFFIX;
+ static final String DEBUG_COLOUR = PREFIX + NORMAL + SEPARATOR + FOREGROUND_CYAN + SUFFIX;
+ static final String TRACE_COLOUR = PREFIX + NORMAL + SEPARATOR + FOREGROUND_BLUE + SUFFIX;
+
+ /**
+ * Wraps the ANSI control characters around the
+ * output from the super-class Appender.
+ */
+ @Override
+ protected void subAppend(LoggingEvent event) {
+ this.qw.write(getColour(event.getLevel()));
+ super.subAppend(event);
+ this.qw.write(END_COLOUR);
+ if (this.immediateFlush) {
+ this.qw.flush();
+ }
+ }
+
+ /**
+ * Get the appropriate control characters to change
+ * the colour for the specified logging level.
+ */
+ private String getColour(org.apache.log4j.Level level) {
+ switch (level.toInt()) {
+ case Priority.FATAL_INT:
+ return FATAL_COLOUR;
+ case Priority.ERROR_INT:
+ return ERROR_COLOUR;
+ case Priority.WARN_INT:
+ return WARN_COLOUR;
+ case Priority.INFO_INT:
+ return INFO_COLOUR;
+ case Priority.DEBUG_INT:
+ return DEBUG_COLOUR;
+ default:
+ return TRACE_COLOUR;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.