diff --git a/framework/src/play/Logger.java b/framework/src/play/Logger.java
index 60b7364894..5218fd7818 100644
--- a/framework/src/play/Logger.java
+++ b/framework/src/play/Logger.java
@@ -2,13 +2,16 @@
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.apache.log4j.Priority;
+import org.apache.log4j.PropertyConfigurator;
import play.exceptions.PlayException;
import play.mvc.Http.Request;
@@ -18,11 +21,27 @@
*/
public class Logger {
- static boolean useJuli = false;
+ public static boolean forceJuli = false;
- public static void setUp(String level) {
- useJuli = Play.configuration.getProperty("logger.juli", "false").equals("true");
- if(useJuli || log4j == null) {
+ /**
+ * The application logger (play).
+ */
+ public static org.apache.log4j.Logger log4j;
+ public static java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
+ static {
+ URL log4jConf = Logger.class.getResource("/log4j.properties");
+ if(log4jConf == null) {
+ Properties shutUp = new Properties();
+ shutUp.setProperty("log4j.rootLogger", "OFF");
+ PropertyConfigurator.configure(shutUp);
+ } else {
+ PropertyConfigurator.configure(log4jConf);
+ Logger.log4j = org.apache.log4j.Logger.getLogger("play");
+ }
+ }
+
+ public static void setUp(String level) {
+ if(forceJuli || log4j == null) {
Logger.juli.setLevel(toJuliLevel(level));
} else {
Logger.log4j.setLevel(org.apache.log4j.Level.toLevel(level));
@@ -47,10 +66,10 @@ static java.util.logging.Level toJuliLevel(String level) {
juliLevel = java.util.logging.Level.WARNING;
}
if(level.equals("DEBUG")) {
- juliLevel = java.util.logging.Level.CONFIG;
+ juliLevel = java.util.logging.Level.FINE;
}
if(level.equals("TRACE")) {
- juliLevel = java.util.logging.Level.FINE;
+ juliLevel = java.util.logging.Level.FINEST;
}
if(level.equals("ALL")) {
juliLevel = java.util.logging.Level.ALL;
@@ -60,27 +79,16 @@ static java.util.logging.Level toJuliLevel(String level) {
}
return juliLevel;
}
-
- /**
- * The application logger (play).
- */
- public static org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger("play");
- static {
- if(!org.apache.log4j.Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
- Logger.log4j = null;
- }
- }
- public static java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
-
+
/**
* Log with TRACE level
* @param message The message pattern
* @param args Pattern arguments
*/
public static void trace(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
- juli.fine(String.format(message, args));
+ juli.finest(String.format(message, args));
} catch (Throwable ex) {
juli.log(Level.SEVERE, "Oops. Error in Logger !", ex);
}
@@ -99,9 +107,9 @@ public static void trace(String message, Object... args) {
* @param args Pattern arguments
*/
public static void debug(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
- juli.config(String.format(message, args));
+ juli.fine(String.format(message, args));
} catch (Throwable ex) {
juli.log(Level.SEVERE, "Oops. Error in Logger !", ex);
}
@@ -121,7 +129,7 @@ public static void debug(String message, Object... args) {
* @param args Pattern arguments
*/
public static void debug(Throwable e, String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
if (!niceThrowable(Priority.DEBUG, e, message, args)) {
juli.log(Level.CONFIG, String.format(message, args), e);
@@ -146,7 +154,7 @@ public static void debug(Throwable e, String message, Object... args) {
* @param args Pattern arguments
*/
public static void info(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
juli.info(String.format(message, args));
} catch (Throwable ex) {
@@ -168,7 +176,7 @@ public static void info(String message, Object... args) {
* @param args Pattern arguments
*/
public static void info(Throwable e, String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
if (!niceThrowable(Priority.INFO, e, message, args)) {
juli.log(Level.INFO, String.format(message, args), e);
@@ -193,7 +201,7 @@ public static void info(Throwable e, String message, Object... args) {
* @param args Pattern arguments
*/
public static void warn(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
juli.warning(String.format(message, args));
} catch (Throwable ex) {
@@ -215,7 +223,7 @@ public static void warn(String message, Object... args) {
* @param args Pattern arguments
*/
public static void warn(Throwable e, String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
if (!niceThrowable(Priority.WARN, e, message, args)) {
juli.log(Level.WARNING, String.format(message, args), e);
@@ -240,7 +248,7 @@ public static void warn(Throwable e, String message, Object... args) {
* @param args Pattern arguments
*/
public static void error(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
juli.severe(String.format(message, args));
} catch (Throwable ex) {
@@ -262,7 +270,7 @@ public static void error(String message, Object... args) {
* @param args Pattern arguments
*/
public static void error(Throwable e, String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
if (!niceThrowable(Priority.ERROR, e, message, args)) {
juli.log(Level.SEVERE, String.format(message, args), e);
@@ -287,7 +295,7 @@ public static void error(Throwable e, String message, Object... args) {
* @param args Pattern arguments
*/
public static void fatal(String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
juli.severe(String.format(message, args));
} catch (Throwable ex) {
@@ -309,7 +317,7 @@ public static void fatal(String message, Object... args) {
* @param args Pattern arguments
*/
public static void fatal(Throwable e, String message, Object... args) {
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
try {
if (!niceThrowable(Priority.FATAL, e, message, args)) {
juli.log(Level.SEVERE, String.format(message, args), e);
@@ -367,7 +375,7 @@ static boolean niceThrowable(Priority priority, Throwable e, String message, Obj
errorOut.println(playException.getErrorTitle());
}
errorOut.println(playException.getErrorDescription().replace("", "").replace("", "").replace("\n", " "));
- if(useJuli || log4j == null) {
+ if(forceJuli || log4j == null) {
juli.log(toJuliLevel(priority.toString()), sw.toString(), e);
} else {
log4j.log(priority, sw.toString(), e);
diff --git a/framework/src/play/Play.java b/framework/src/play/Play.java
index 37a12ac257..063171e02a 100644
--- a/framework/src/play/Play.java
+++ b/framework/src/play/Play.java
@@ -130,6 +130,8 @@ public static void init(File root, String id) {
Play.id = id;
Play.started = false;
Play.applicationPath = root;
+
+ initStaticStuff();
// Guess the framework path
try {
@@ -284,7 +286,7 @@ public static synchronized void start() {
readConfiguration();
if (configuration.getProperty("play.tmp", "tmp").equals("none")) {
tmpDir = null;
- Logger.warn("No tmp folder will be used (play.tmp is set to none)");
+ Logger.debug("No tmp folder will be used (play.tmp is set to none)");
} else {
tmpDir = new File(configuration.getProperty("play.tmp", "tmp"));
if (!tmpDir.isAbsolute()) {
@@ -418,7 +420,7 @@ public static void loadPlugins() {
urls = Play.classloader.getResources("play.plugins");
} catch (Exception e) {
}
- while (urls.hasMoreElements()) {
+ while (urls != null && urls.hasMoreElements()) {
URL url = urls.nextElement();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
@@ -438,11 +440,36 @@ public static void loadPlugins() {
plugin.onLoad();
}
}
-
- public static void addPlugins(URL playPluginManifest) {
-
+
+ /**
+ * Allow some code to run very eraly in Play! - Use with caution !
+ */
+ public static void initStaticStuff() {
+ // Play! plugings
+ Enumeration urls = null;
+ try {
+ urls = Play.class.getClassLoader().getResources("play.static");
+ } catch (Exception e) {
+ }
+ while (urls != null && urls.hasMoreElements()) {
+ URL url = urls.nextElement();
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ try {
+ Class.forName(line);
+ } catch(Exception e) {
+ System.out.println("! Cannot init static : " + line);
+ }
+ }
+ } catch (Exception ex) {
+ Logger.error(ex, "Cannot load %s", url);
+ }
+ }
}
+
public static void loadModules() {
if (System.getenv("MODULES") != null) {
// Modules path is prepended with a env property
diff --git a/framework/src/play/PlayPlugin.java b/framework/src/play/PlayPlugin.java
index 09d3f34d3e..37e06da30d 100644
--- a/framework/src/play/PlayPlugin.java
+++ b/framework/src/play/PlayPlugin.java
@@ -129,12 +129,6 @@ public void afterActionInvocation() {
public void onConfigurationRead() {
}
- /**
- * Called when the server is ready.
- */
- public void onServerReady() {
- }
-
/**
* Called after routes loading.
*/
diff --git a/framework/src/play/classloading/enhancers/PropertiesEnhancer.java b/framework/src/play/classloading/enhancers/PropertiesEnhancer.java
index 3392e50186..1771bec874 100644
--- a/framework/src/play/classloading/enhancers/PropertiesEnhancer.java
+++ b/framework/src/play/classloading/enhancers/PropertiesEnhancer.java
@@ -21,8 +21,8 @@
* Generate valid JavaBeans.
*/
public class PropertiesEnhancer extends Enhancer {
-
- @Override
+
+ @Override
public void enhanceThisClass(ApplicationClass applicationClass) throws Exception {
final CtClass ctClass = makeClass(applicationClass);
if (ctClass.isInterface()) {
diff --git a/framework/src/play/db/jpa/JPAPlugin.java b/framework/src/play/db/jpa/JPAPlugin.java
index 505804deb3..f17a9d5327 100644
--- a/framework/src/play/db/jpa/JPAPlugin.java
+++ b/framework/src/play/db/jpa/JPAPlugin.java
@@ -45,7 +45,7 @@ public void onApplicationStart() {
for (Class clazz : classes) {
if (clazz.isAnnotationPresent(Entity.class)) {
cfg.addAnnotatedClass(clazz);
- Logger.debug("JPA Model : %s", clazz);
+ Logger.trace("JPA Model : %s", clazz);
}
}
Logger.debug("Initializing JPA ...");
diff --git a/framework/src/play/libs/Java.java b/framework/src/play/libs/Java.java
index e7b45b88b3..91b8e78014 100644
--- a/framework/src/play/libs/Java.java
+++ b/framework/src/play/libs/Java.java
@@ -173,7 +173,7 @@ public static void findAllFields(Class clazz, Set found) {
public static FieldWrapper getFieldWrapper(Field field) {
if (wrappers.get(field) == null) {
FieldWrapper fw = new FieldWrapper(field);
- play.Logger.debug("caching %s", fw);
+ play.Logger.trace("caching %s", fw);
wrappers.put(field, fw);
}
return wrappers.get(field);
@@ -226,13 +226,13 @@ public void setValue(Object instance, Object value) {
}
try {
if (setter != null) {
- play.Logger.debug("invoke setter %s on %s with value %s", setter, instance, value);
+ play.Logger.trace("invoke setter %s on %s with value %s", setter, instance, value);
setter.invoke(instance, value);
} else {
if (!accessible) {
field.setAccessible(true);
}
- play.Logger.debug("field.set(%s, %s)", instance, value);
+ play.Logger.trace("field.set(%s, %s)", instance, value);
field.set(instance, value);
if (!accessible) {
field.setAccessible(accessible);
diff --git a/framework/src/play/mvc/Router.java b/framework/src/play/mvc/Router.java
index 1208f0c8cd..ec34a85b4b 100644
--- a/framework/src/play/mvc/Router.java
+++ b/framework/src/play/mvc/Router.java
@@ -145,7 +145,7 @@ public static void route(Http.Request request) {
if (request.querystring != null && methodOverride.matches(request.querystring)) {
Matcher matcher = methodOverride.matcher(request.querystring);
if (matcher.matches()) {
- Logger.debug("request method %s overriden to %s ", request.method, matcher.group("method"));
+ Logger.trace("request method %s overriden to %s ", request.method, matcher.group("method"));
request.method = matcher.group("method");
}
}
diff --git a/framework/src/play/server/Server.java b/framework/src/play/server/Server.java
index fafa4df23d..65c74f15b9 100644
--- a/framework/src/play/server/Server.java
+++ b/framework/src/play/server/Server.java
@@ -50,11 +50,8 @@ public Server() {
Logger.error("Could not bind on port " + httpPort, e);
acceptor.dispose();
}
-
- // Plugins
- for (PlayPlugin plugin : Play.plugins) {
- plugin.onServerReady();
- }
+
+ Logger.info("");
}
public static void main(String[] args) {
diff --git a/modules/gae/build.xml b/modules/gae/build.xml
index 8b082e1901..869298a46b 100644
--- a/modules/gae/build.xml
+++ b/modules/gae/build.xml
@@ -25,6 +25,7 @@
+
diff --git a/modules/gae/src/play.static b/modules/gae/src/play.static
new file mode 100644
index 0000000000..822fe2e001
--- /dev/null
+++ b/modules/gae/src/play.static
@@ -0,0 +1 @@
+play.modules.gae.GAEInit
\ No newline at end of file
diff --git a/modules/gae/src/play/modules/gae/GAECache.java b/modules/gae/src/play/modules/gae/GAECache.java
index 14de772409..5e39512d77 100644
--- a/modules/gae/src/play/modules/gae/GAECache.java
+++ b/modules/gae/src/play/modules/gae/GAECache.java
@@ -110,7 +110,7 @@ Object unwrap(Object bytes) {
@Override
protected Class> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
- return Play.classloader.loadClass(desc.getName());
+ return Class.forName(desc.getName(), false, Play.classloader);
}
}.readObject();
} catch (Exception e) {
diff --git a/modules/gae/src/play/modules/gae/GAEInit.java b/modules/gae/src/play/modules/gae/GAEInit.java
new file mode 100644
index 0000000000..6a9685af47
--- /dev/null
+++ b/modules/gae/src/play/modules/gae/GAEInit.java
@@ -0,0 +1,18 @@
+package play.modules.gae;
+
+import com.google.apphosting.api.ApiProxy;
+import org.apache.log4j.helpers.LogLog;
+import play.Logger;
+
+public class GAEInit {
+
+ static {
+ if(ApiProxy.getCurrentEnvironment() != null) {
+ LogLog.setQuietMode(true);
+ Logger.forceJuli = true;
+ Logger.setUp("DEBUG");
+ Logger.info("Play! is running in Google App Engine");
+ }
+ }
+
+}
diff --git a/modules/gae/src/play/modules/gae/GAEPlugin.java b/modules/gae/src/play/modules/gae/GAEPlugin.java
index b25b2dcd58..46160dc756 100644
--- a/modules/gae/src/play/modules/gae/GAEPlugin.java
+++ b/modules/gae/src/play/modules/gae/GAEPlugin.java
@@ -25,6 +25,7 @@
public class GAEPlugin extends PlayPlugin {
public ApiProxy.Environment devEnvironment = null;
+ public boolean prodGAE;
@Override
public void onLoad() {
@@ -37,6 +38,7 @@ public void onLoad() {
// Force to PROD mode when hosted on production GAE
if(ApiProxy.getCurrentEnvironment() != null && ApiProxy.getCurrentEnvironment().getClass().getName().indexOf("development") == -1) {
Play.mode = Play.Mode.PROD;
+ prodGAE = true;
}
// Create a fake development environment if not run in the Google SDK
if(ApiProxy.getCurrentEnvironment() == null) {
@@ -142,6 +144,9 @@ public void beforeInvocation() {
public void onConfigurationRead() {
// Disable tmp directory
Play.configuration.setProperty("play.tmp", "none");
+ if(devEnvironment == null) {
+ Play.configuration.setProperty("application.log", "DEBUG");
+ }
}
}
diff --git a/modules/test-runner/src/play/modules/testrunner/TestRunnerPlugin.java b/modules/test-runner/src/play/modules/testrunner/TestRunnerPlugin.java
index 4765230a3e..14d404a3fa 100644
--- a/modules/test-runner/src/play/modules/testrunner/TestRunnerPlugin.java
+++ b/modules/test-runner/src/play/modules/testrunner/TestRunnerPlugin.java
@@ -7,16 +7,17 @@
public class TestRunnerPlugin extends PlayPlugin {
+ @Override
+ public void onLoad() {
+ Logger.info("");
+ Logger.info("Go to http://localhost:" + Server.port + "/@tests to run the tests");
+ Logger.info("");
+ }
+
@Override
public void onRoutesLoaded() {
Router.addRoute("GET", "/@tests", "TestRunner.index");
Router.addRoute("GET", "/@tests/{test}", "TestRunner.run");
}
- @Override
- public void onServerReady() {
- Logger.info("");
- Logger.info("Go to http://localhost:" + Server.port + "/@tests to run the tests");
- Logger.info("");
- }
}
diff --git a/play b/play
index 5c0955d6ba..10cf95851f 100755
--- a/play
+++ b/play
@@ -553,7 +553,7 @@ try:
shutil.rmtree(nbproject)
if os.name == 'nt':
time.sleep(1)
- shutil.copytree(os.path.join(play_base, 'resources/nbproject'), nbproject)
+ shutil.copytree(os.path.join(play_base, 'resources/_nbproject'), nbproject)
replaceAll(os.path.join(nbproject, 'project.xml'), r'%APPLICATION_NAME%', application_name)
replaceAll(os.path.join(nbproject, 'project.xml'), r'%ANT_SCRIPT%', os.path.normpath(os.path.join(play_base, 'framework/build.xml')))
replaceAll(os.path.join(nbproject, 'project.xml'), r'%APPLICATION_PATH%', os.path.normpath(application_path))
diff --git a/resources/nbproject/project.xml b/resources/_nbproject/project.xml
similarity index 100%
rename from resources/nbproject/project.xml
rename to resources/_nbproject/project.xml