packages: introduce syslog function in gluon.util

This commit introduces a simple function for writing to the syslog and
replaces the custom function used by gluon-hoodselector.
This commit is contained in:
CodeFetch 2020-12-20 22:45:55 +01:00
parent 049625bb14
commit 50313697c7
3 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,6 @@
local bit = require 'bit'
local posix_glob = require 'posix.glob'
local posix_syslog = require 'posix.syslog'
local hash = require 'hash'
local sysconfig = require 'gluon.sysconfig'
local site = require 'gluon.site'
@ -179,4 +180,12 @@ function M.get_uptime()
return tonumber(uptime_file:match('^[^ ]+'))
end
function M.log(message, verbose)
if verbose then
io.stdout:write(message .. '\n')
end
posix_syslog.syslog(posix_syslog.LOG_INFO, message)
end
return M

View File

@ -3,14 +3,8 @@ local math_polygon = require('math-polygon')
local json = require ('jsonc')
local uci = require('simple-uci').cursor()
local site = require ('gluon.site')
local logger = require('posix.syslog')
local M = {}
function M.log(msg)
io.stdout:write(msg..'\n')
logger.openlog(msg, logger.LOG_PID)
end
function M.get_domains()
local list = {}
for _, domain_path in ipairs(util.glob('/lib/gluon/domains/*.json')) do
@ -68,7 +62,7 @@ end
function M.set_domain_config(domain)
if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then
os.execute(string.format("exec gluon-switch-domain --no-reboot '%s'", domain.domain_code))
M.log('Set domain "'..domain.domain.domain_names[domain.domain_code]..'"')
util.log('Set domain "' .. domain.domain.domain_names[domain.domain_code] .. '"', true)
return true
end
return false

View File

@ -1,6 +1,7 @@
#!/usr/bin/lua
local bit = require('bit')
local util = require ('gluon.util')
local unistd = require('posix.unistd')
local fcntl = require('posix.fcntl')
local hoodutil = require('hoodselector.util')
@ -10,7 +11,7 @@ local lockfile = '/var/lock/hoodselector.lock'
local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600
if not lockfd then
hoodutil.log(err, '\n')
util.log(err, true)
os.exit(1)
end
@ -40,7 +41,7 @@ if geo.lat ~= nil and geo.lon ~= nil then
local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo)
if geo_base_domain ~= nil then
if hoodutil.set_domain_config(geo_base_domain) then
hoodutil.log('Domain set by geolocation mode.\n')
util.log('Domain set by geolocation mode.', true)
end
return
end