comparison src/error_log.js.luan @ 7:0472897e790d

add javascript
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 23 Jun 2022 23:38:03 -0600
parents
children a1db5223ced1
comparison
equal deleted inserted replaced
6:9166f6a14021 7:0472897e790d
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local String = require "luan:String.luan"
4 local matches = String.matches or error()
5 local trim = String.trim or error()
6 local Table = require "luan:Table.luan"
7 local Http = require "luan:http/Http.luan"
8 local Logging = require "luan:logging/Logging.luan"
9 local logger = Logging.logger "error_log"
10
11 --[=[ when needed
12 local bad_bots = {
13 [[Googlebot]]
14 [[bingbot]]
15 }
16 local bad_bots_ptn = Table.concat(bad_bots,"|")
17 ]=]
18
19 local function priority(err)
20 --[=[
21 local agent = Http.request.headers["user-agent"]
22 if agent~=nil and matches(agent,bad_bots_ptn) then return "info" end
23 if matches(err,[[Uncaught TypeError: Illegal invocation]]) then return "warn" end
24 if matches(err,[[\Q?fbclid=\E]]) then return "warn" end
25 ]=]
26 return "error"
27 end
28
29 return function()
30 local err = Http.request.parameters.err
31 if err == nil then
32 return -- stupid bots
33 end
34 local call = priority(err)
35 logger[call](trim(err).."\n"..trim(Http.request.raw_head).."\n")
36 end