Mercurial Hosting > luan
changeset 207:5aafb5b9f70f
various
git-svn-id: https://luan-java.googlecode.com/svn/trunk@208 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 08 Jul 2014 02:04:24 +0000 |
parents | 77365c9fdfe4 |
children | 5ba136769034 |
files | core/src/luan/init.luan core/src/luan/modules/PackageLuan.java logging/src/luan/modules/logging/Logging.luan web/src/luan/modules/web/Web_server.luan |
diffstat | 4 files changed, 33 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
diff -r 77365c9fdfe4 -r 5aafb5b9f70f core/src/luan/init.luan --- a/core/src/luan/init.luan Mon Jul 07 23:55:52 2014 +0000 +++ b/core/src/luan/init.luan Tue Jul 08 02:04:24 2014 +0000 @@ -44,7 +44,15 @@ if path == nil then error("module '"..mod_name.."' not found") end - Package.block_lib(path) + Package.block_path(path) +end + +function Package.is_blocked(mod_name) + local fn,path = Package.search(mod_name) + if path == nil then + error("module '"..mod_name.."' not found") + end + return Package.is_blocked_path(path) end function Io.print_to(out,...)
diff -r 77365c9fdfe4 -r 5aafb5b9f70f core/src/luan/modules/PackageLuan.java --- a/core/src/luan/modules/PackageLuan.java Mon Jul 07 23:55:52 2014 +0000 +++ b/core/src/luan/modules/PackageLuan.java Tue Jul 08 02:04:24 2014 +0000 @@ -27,7 +27,8 @@ module.put( "jpath", jpath ); try { module.put("require",requireFn); - add( module, "block_lib", LuanState.class, String.class ); + add( module, "block_path", LuanState.class, String.class ); + add( module, "is_blocked_path", LuanState.class, String.class ); add( module, "load", LuanState.class, String.class ); add( module, "load_lib", LuanState.class, String.class ); add( module, "search_path", String.class, String.class ); @@ -203,14 +204,18 @@ }; - public static void block_lib(LuanState luan,String path) { + public static void block_path(LuanState luan,String path) { blocked(luan).put(path,true); } + public static boolean is_blocked_path(LuanState luan,String path) { + return blocked(luan).get(path) != null; + } + public static LuanFunction load_lib(LuanState luan,String path) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException { - if( blocked(luan).get(path) != null ) + if( is_blocked_path(luan,path) ) throw luan.exception(path+" is blocked"); int i = path.lastIndexOf('.'); String clsPath = path.substring(0,i);
diff -r 77365c9fdfe4 -r 5aafb5b9f70f logging/src/luan/modules/logging/Logging.luan --- a/logging/src/luan/modules/logging/Logging.luan Mon Jul 07 23:55:52 2014 +0000 +++ b/logging/src/luan/modules/logging/Logging.luan Tue Jul 08 02:04:24 2014 +0000 @@ -1,3 +1,10 @@ +import "Package" + +if Package.is_blocked "logging/Logging" then + error "Logging is blocked" +end + + import "Java" import "org.apache.log4j.Logger" import "org.apache.log4j.EnhancedPatternLayout" @@ -14,7 +21,7 @@ file = nil -- set to file name if you want logging to a file -max_file_size = "10MB" +max_file_size = nil -- by default is "10MB" log4j_root_logger = Logger.getRootLogger() @@ -23,11 +30,11 @@ return level and Level.toLevel(level) end -function log_to_file(file) +function log_to_file(file,logger_name) -- logger_name is optional, defaults to root logger local appender = RollingFileAppender.new(ptn_layout, file) appender.setMaxFileSize(max_file_size) - print("getMaximumFileSize",appender.getMaximumFileSize()) - log4j_root_logger.addAppender(appender) + local logger = logger_name and Logger.getLogger(logger_name) or log4j_root_logger + logger.addAppender(appender) return appender end
diff -r 77365c9fdfe4 -r 5aafb5b9f70f web/src/luan/modules/web/Web_server.luan --- a/web/src/luan/modules/web/Web_server.luan Mon Jul 07 23:55:52 2014 +0000 +++ b/web/src/luan/modules/web/Web_server.luan Tue Jul 08 02:04:24 2014 +0000 @@ -38,6 +38,7 @@ function add_folder(context,dir) local rh = ResourceHandler.new() rh.setResourceBase(dir) + rh.setDirectoriesListed(true) local ch = ContextHandler.new(context) ch.setHandler(rh) handlers.addHandler(ch) @@ -58,6 +59,10 @@ log_handler = RequestLogHandler.new() log_handler.setRequestLog(log) +function set_log_file(file_name) + log.setFilename(file_name) +end + local hc = HandlerCollection.new() hc.setHandlers { SessionHandler.new(), handler_wrapper, DefaultHandler.new(), log_handler }