annotate src/error_log.js.luan @ 93:d0566cc4a2ac default tip

uploa fix
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Apr 2025 19:47:48 -0600
parents 5240c054dcd4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local String = require "luan:String.luan"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local trim = String.trim or error()
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local regex = String.regex or error()
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local contains = String.contains or error()
90
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
7 local Table = require "luan:Table.luan"
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
8 local concat = Table.concat or error()
3
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Http = require "luan:http/Http.luan"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Logging = require "luan:logging/Logging.luan"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local logger = Logging.logger "error_log.js"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
90
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
14 local bad_agents = {
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
15 [[Version/14\.]]
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
16 }
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
17 local bad_agents_ptn = regex(concat(bad_agents,"|"))
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
18
3
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local function priority(err)
90
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
20 local agent = Http.request.headers["user-agent"]
5240c054dcd4 logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
21 if agent~=nil and bad_agents_ptn.matches(agent) then return "info" end
3
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 return "error"
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return function()
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local err = Http.request.parameters.err
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 if err == nil then
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 return -- stupid bots
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 end
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 local call = priority(err)
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 logger[call](trim(err).."\n"..trim(Http.request.raw_head).."\n")
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 end