annotate src/error_log.js.luan @ 22:d87a8f9f43d7

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