-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshared.lua
More file actions
79 lines (66 loc) · 2.33 KB
/
Copy pathshared.lua
File metadata and controls
79 lines (66 loc) · 2.33 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
69
70
71
72
73
74
75
76
77
78
79
Locales = Locales or {}
function _L(key, ...)
local lang = (F5Cfg and F5Cfg.Locale) or 'en'
local s = (Locales[lang] and Locales[lang][key])
or (Locales['en'] and Locales['en'][key])
or key
if select('#', ...) > 0 then
local ok, res = pcall(string.format, s, ...)
if ok then return res end
end
return s
end
function Translate(key, ...)
return _L(key, ...)
end
function BuildLocaleBundle()
local lang = (F5Cfg and F5Cfg.Locale) or 'en'
local out = {}
local enFB = Locales['en'] or {}
for k, v in pairs(enFB) do out[k] = v end
local active = Locales[lang]
if active and active ~= enFB then
for k, v in pairs(active) do out[k] = v end
end
return out
end
Debug = {}
local LAYER = IsDuplicityVersion() and 'SERVER' or 'CLIENT'
local _unknownCatWarned = {}
local function shouldLog(category)
if not F5Cfg or not F5Cfg.Debug then return false end
if not F5Cfg.Debug.enabled then return false end
local state = F5Cfg.Debug.categories[category]
if state == nil then
if not _unknownCatWarned[category] then
_unknownCatWarned[category] = true
print(('^1[%s][DEBUG]^0 unknown category: %s (call site bug)')
:format(LAYER, tostring(category)))
end
return false
end
if not state then return false end
return true
end
local function emit(category, severity, msg, ...)
if not shouldLog(category) then return end
local color = (F5Cfg.Debug.colors and F5Cfg.Debug.colors[category]) or '^7'
local sev = (F5Cfg.Debug.severityPrefix and F5Cfg.Debug.severityPrefix[severity]) or ''
if select('#', ...) > 0 then
local ok, formatted = pcall(string.format, msg, ...)
if ok then msg = formatted end
end
print(('%s[%s][%s]^0 %s%s'):format(color, LAYER, category, sev, tostring(msg)))
end
function Debug.log(category, msg, ...) emit(category, 'info', msg, ...) end
function Debug.warn(category, msg, ...) emit(category, 'warn', msg, ...) end
function Debug.err(msg, ...) emit('ERROR', 'err', msg, ...) end
function Debug.buildNuiPayload()
if not F5Cfg or not F5Cfg.Debug then
return { enabled = false, categories = {} }
end
return {
enabled = F5Cfg.Debug.enabled,
categories = F5Cfg.Debug.categories,
}
end