forked from sourcegraph/sg.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.lua
More file actions
68 lines (56 loc) · 1.13 KB
/
Copy pathlog.lua
File metadata and controls
68 lines (56 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local traverse
traverse = function(t, f)
for k, v in pairs(t) do
f(t, k, v)
if type(v) == "table" then
traverse(v, f)
end
end
end
local logger = require("plenary.log").new {
plugin = "sg",
level = "info",
use_console = false,
info_level = 3,
}
-- logger.
local modes = {
"trace",
"debug",
"info",
"warn",
"error",
"fatal",
}
local filtered_keys = {
SRC_ACCESS_TOKEN = true,
accessToken = true,
token = true,
}
local shortened_keys = {
content = true,
}
local modified = {}
for _, level in ipairs(modes) do
modified[level] = function(...)
local arguments = { ... }
for idx, arg in ipairs(arguments) do
if type(arg) == "table" then
arg = vim.deepcopy(arg)
traverse(arg, function(t, k, v)
if filtered_keys[k] then
t[k] = "**** revoked ****"
end
if shortened_keys[k] then
if type(v) == "string" and #v > 15 then
t[k] = string.sub(v, 1, 15) .. " ..."
end
end
end)
arguments[idx] = arg
end
end
logger[level](unpack(arguments))
end
end
return modified