comparison src/luan/host/Init.luan @ 1135:707a5d874f3e

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