annotate host/run.luan @ 1633:665049cffc02

fix path
author fffilimonov
date Tue, 14 Dec 2021 07:55:47 -0600
parents 520707a70379
children 48c24eedb8b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1628
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 require "java"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local Luan = require "luan:Luan.luan"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local error = Luan.error
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local ipairs = Luan.ipairs or error()
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Number = require "luan:Number.luan"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local long = Number.long or error()
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Logging = require "luan:logging/Logging.luan"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local log_to_console = false
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 for _, arg in ipairs{...} do
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 if arg == "console" then
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 log_to_console = true
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 end
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 end
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 if not log_to_console then
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local LuanLogger = require "java:luan.modules.logging.LuanLogger"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local Layouts = require "java:goodjava.logger.Layouts"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local DateLayout = require "java:goodjava.logger.DateLayout"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local ListLayout = require "java:goodjava.logger.ListLayout"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local Level = require "java:goodjava.logger.Level"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local RollingFileAppender = require "java:goodjava.logger.RollingFileAppender"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 local LevelAppender = require "java:goodjava.logger.LevelAppender"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 local ListAppender = require "java:goodjava.logger.ListAppender"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local one_mb = long(1024*1024)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local layout = ListLayout.new(DateLayout.new("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 local function new_appender(file,level)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 local appender = RollingFileAppender.new(layout, file)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 appender.maxFileSize = one_mb
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 appender = LevelAppender.new(appender,level)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 return appender
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 end
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 local err = new_appender("logs/luan_error.log",Level.ERROR)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 local warn = new_appender("logs/luan_warn.log",Level.WARN)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 local info = new_appender("logs/luan_info.log",Level.INFO)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 local appender = ListAppender.new(err,warn,info)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 LuanLogger.configure(appender)
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 end
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 local logger = Logging.logger "luanhost-run"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 local do_file = Luan.do_file or error()
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 local WebHandler = require "java:luan.host.WebHandler"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 WebHandler.config = require "file:Config.luan"
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
520707a70379 add host
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 do_file "classpath:luan/host/run.luan"