1170
|
1 require "luan:http/jetty/use_jetty.luan"
|
1135
|
2 local Luan = require "luan:Luan.luan"
|
|
3 local error = Luan.error
|
|
4 local String = require "luan:String.luan"
|
|
5 local gsub = String.gsub or error()
|
|
6 local Io = require "luan:Io.luan"
|
|
7 local Http = require "luan:http/Http.luan"
|
|
8 local Hosting = require "luan:host/Hosting.luan"
|
|
9 local Mail = require "luan:mail/Mail.luan"
|
|
10
|
|
11
|
|
12 local Init = {}
|
|
13
|
|
14 local dir, domain = ...
|
|
15
|
|
16 Init.password = Io.schemes.file(dir).child("password").read_text()
|
|
17
|
|
18 Http.dir = "file:"..dir.."/site"
|
|
19
|
|
20 function Io.schemes.site(path,loading)
|
|
21 return Io.uri( Http.dir..path, loading )
|
|
22 end
|
|
23
|
|
24 Hosting.domain = domain
|
|
25 Io.password = Init.password
|
|
26
|
|
27
|
|
28 -- logging
|
|
29
|
|
30 java()
|
|
31 local Logger = require "java:org.apache.log4j.Logger"
|
|
32 local Logging = require "luan:logging/Logging.luan"
|
|
33
|
|
34 local root = gsub(domain,"\.",":")
|
|
35
|
|
36 Logging.layout = "%d %-5p %c{-1} - %m%n"
|
|
37 Logging.file = dir.."/site/private/local/logs/luan.log"
|
|
38 Logging.max_file_size = "1MB"
|
|
39 local one_mb = 1048576
|
|
40
|
|
41 local log_dir = dir.."/site/private/local/logs/"
|
|
42 Logging.appenders = {
|
|
43 [log_dir.."error.log"] = "ERROR"
|
|
44 [log_dir.."warn.log"] = "WARN"
|
|
45 [log_dir.."info.log"] = "INFO"
|
|
46 }
|
|
47
|
|
48 Logging.log4j_root_logger = Logger.getLogger(root)
|
|
49 Logging.log4j_root_logger.setAdditivity(false)
|
|
50
|
|
51 local old_log_to_file = Logging.log_to_file
|
|
52
|
|
53 function Logging.log_to_file(file,logger_name)
|
|
54 Io.schemes.file(file) -- security check
|
|
55 logger_name = logger_name and root .. "." .. logger_name
|
|
56 local appender = old_log_to_file(file,logger_name)
|
|
57 appender.getMaximumFileSize() <= one_mb or error "Logging.max_file_size is too big"
|
|
58 return appender
|
|
59 end
|
|
60
|
|
61 local old_init = Logging.init
|
|
62
|
|
63 function Logging.init()
|
|
64 Logging.appenders["System.err"] = nil
|
|
65 Logging.appenders["System.out"] = nil
|
|
66 old_init()
|
|
67 end
|
|
68
|
|
69 Logging.init()
|
|
70
|
|
71 local old_logger = Logging.logger
|
|
72
|
|
73 function Logging.root_logger()
|
|
74 return old_logger(root)
|
|
75 end
|
|
76
|
|
77 function Logging.logger(name)
|
|
78 return old_logger( root .. "." .. name )
|
|
79 end
|
|
80
|
|
81 Init.logger_root = root.."."
|
|
82
|
|
83
|
|
84 -- mail - fix later
|
|
85
|
|
86 Hosting.send_mail = Mail.Sender{
|
|
87 host = "smtpcorp.com";
|
|
88 username = "smtp@luanhost.com"; -- ?
|
|
89 password = "luanhost";
|
|
90 port = 2525;
|
|
91 }.send
|
|
92
|
|
93
|
|
94 return Init
|