Mercurial Hosting > luan
comparison src/luan/host/WebHandler.java @ 1321:307e76ccd0d6
generalize separate logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Feb 2019 22:36:55 -0700 |
parents | 5763597ca5c0 |
children | f41919741100 |
comparison
equal
deleted
inserted
replaced
1320:2c8d1d76a82a | 1321:307e76ccd0d6 |
---|---|
11 import luan.LuanException; | 11 import luan.LuanException; |
12 import luan.LuanTable; | 12 import luan.LuanTable; |
13 import luan.modules.IoLuan; | 13 import luan.modules.IoLuan; |
14 import luan.modules.JavaLuan; | 14 import luan.modules.JavaLuan; |
15 import luan.modules.http.LuanHandler; | 15 import luan.modules.http.LuanHandler; |
16 import luan.modules.logging.LuanLogger; | |
16 | 17 |
17 | 18 |
18 public class WebHandler implements Handler { | 19 public class WebHandler implements Handler { |
19 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); | 20 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); |
20 | 21 |
27 | 28 |
28 String logDir = dirStr + "/site/private/local/logs/web"; | 29 String logDir = dirStr + "/site/private/local/logs/web"; |
29 new File(logDir).mkdirs(); | 30 new File(logDir).mkdirs(); |
30 | 31 |
31 LuanState luan = new LuanState(); | 32 LuanState luan = new LuanState(); |
32 LuanTable init = initLuan(luan,dirStr,domain); | 33 try { |
33 String loggerRoot = (String)init.rawGet("logger_root"); | 34 LuanLogger.newLoggerRepository(luan); |
34 return new LuanHandler(luan,loggerRoot); | 35 } catch(LuanException e) { |
36 throw new RuntimeException(e); | |
37 } | |
38 initLuan(luan,dirStr,domain,true); | |
39 return new LuanHandler(luan); | |
35 } | 40 } |
36 }; | 41 }; |
37 | 42 |
38 public static String allowJavaFileName = "allow_java"; // change for security | 43 public static String allowJavaFileName = "allow_java"; // change for security |
39 private static final DomainHandler domainHandler = new DomainHandler(factory); | 44 private static final DomainHandler domainHandler = new DomainHandler(factory); |
83 throw new RuntimeException("couldn't rename "+from+" to "+dir); | 88 throw new RuntimeException("couldn't rename "+from+" to "+dir); |
84 logger.info("recovered "+name+" from "+from); | 89 logger.info("recovered "+name+" from "+from); |
85 return true; | 90 return true; |
86 } | 91 } |
87 */ | 92 */ |
88 static LuanTable initLuan(LuanState luan,String dir,String domain) { | 93 static LuanTable initLuan(LuanState luan,String dir,String domain,boolean logging) { |
89 LuanTable init; | 94 LuanTable init; |
90 try { | 95 try { |
91 init = (LuanTable)luan.eval( | 96 init = (LuanTable)luan.eval( |
92 "local Luan = require 'luan:Luan.luan'\n" | 97 "local Luan = require 'luan:Luan.luan'\n" |
93 +"local f = Luan.load_file 'classpath:luan/host/Init.luan'\n" | 98 +"local f = Luan.load_file 'classpath:luan/host/Init.luan'\n" |
94 +"return f('"+dir+"','"+domain+"')\n" | 99 +"return f('"+dir+"','"+domain+"',"+logging+")\n" |
95 ); | 100 ); |
96 } catch(LuanException e) { | 101 } catch(LuanException e) { |
97 throw new RuntimeException(e); | 102 throw new RuntimeException(e); |
98 } | 103 } |
99 File allowJavaFile = new File(dir,"site/private/"+allowJavaFileName); | 104 File allowJavaFile = new File(dir,"site/private/"+allowJavaFileName); |