Mercurial Hosting > luan
annotate src/luan/host/Init.luan @ 1235:22228c12b6dd
fix luanhost thread logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 21 Apr 2018 21:54:23 -0600 |
parents | 3995cbe5b00a |
children | 3d29033de2bf |
rev | line source |
---|---|
1135 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
3 local String = require "luan:String.luan" | |
4 local gsub = String.gsub or error() | |
5 | |
6 | |
7 local Init = {} | |
8 | |
9 local dir, domain = ... | |
10 | |
11 | |
12 -- logging | |
13 | |
14 java() | |
15 local Logger = require "java:org.apache.log4j.Logger" | |
1199 | 16 local Level = require "java:org.apache.log4j.Level" |
17 local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" | |
18 local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" | |
1135 | 19 |
20 local root = gsub(domain,"\.",":") | |
21 | |
1199 | 22 local logger = Logger.getLogger(root) |
23 local has_appenders = logger.getAllAppenders().hasMoreElements() | |
24 if not has_appenders then | |
25 logger.setAdditivity(false) | |
26 local layout = EnhancedPatternLayout.new("%d %-5p %c{-1} - %m%n") | |
27 local log_dir = dir.."/site/private/local/logs/" | |
1135 | 28 |
1199 | 29 local function add_appender(file,level) |
30 local appender = RollingFileAppender.new(layout, log_dir..file) | |
31 appender.setMaxFileSize("1MB") | |
32 logger.addAppender(appender) | |
33 if level ~= logger.getEffectiveLevel() then | |
34 appender.setThreshold(level) | |
35 end | |
36 end | |
1135 | 37 |
1199 | 38 add_appender("error.log",Level.ERROR) |
39 add_appender("warn.log",Level.WARN) | |
40 add_appender("info.log",Level.INFO) | |
1135 | 41 end |
42 | |
1199 | 43 local Logging = require "luan:logging/Logging.luan" |
1135 | 44 |
45 local old_logger = Logging.logger | |
46 | |
47 function Logging.root_logger() | |
48 return old_logger(root) | |
49 end | |
50 | |
51 function Logging.logger(name) | |
52 return old_logger( root .. "." .. name ) | |
53 end | |
54 | |
55 Init.logger_root = root.."." | |
56 | |
57 | |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
58 -- set vars |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
59 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
60 local Io = require "luan:Io.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
61 local Http = require "luan:http/Http.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
62 local Hosting = require "luan:host/Hosting.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
63 local Mail = require "luan:mail/Mail.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
64 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
65 Init.password = Luan.do_file(dir.."/info.luan").password or error() |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
66 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
67 Http.dir = "file:"..dir.."/site" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
68 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
69 function Io.schemes.site(path,loading) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
70 return Io.uri( Http.dir..path, loading ) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
71 end |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
72 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
73 Hosting.domain = domain |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
74 Io.password = Init.password |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
75 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
76 |
1135 | 77 -- mail - fix later |
78 | |
79 Hosting.send_mail = Mail.Sender{ | |
80 host = "smtpcorp.com"; | |
81 username = "smtp@luanhost.com"; -- ? | |
82 password = "luanhost"; | |
83 port = 2525; | |
84 }.send | |
85 | |
86 | |
87 return Init |