mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2024-11-23 22:00:11 +00:00
34 lines
814 B
Lua
34 lines
814 B
Lua
|
-------------------------------------------------------------------------------
|
||
|
-- Sends the logging information through a socket using luasocket
|
||
|
--
|
||
|
-- @author Thiago Costa Ponte (thiago@ideais.com.br)
|
||
|
--
|
||
|
-- @copyright 2004-2013 Kepler Project
|
||
|
--
|
||
|
-------------------------------------------------------------------------------
|
||
|
|
||
|
local logging = require"logging"
|
||
|
local socket = require"socket"
|
||
|
|
||
|
function logging.socket(address, port, logPattern)
|
||
|
return logging.new( function(self, level, message)
|
||
|
local s = logging.prepareLogMsg(logPattern, os.date(), level, message)
|
||
|
|
||
|
local socket, err = socket.connect(address, port)
|
||
|
if not socket then
|
||
|
return nil, err
|
||
|
end
|
||
|
|
||
|
local cond, err = socket:send(s)
|
||
|
if not cond then
|
||
|
return nil, err
|
||
|
end
|
||
|
socket:close()
|
||
|
|
||
|
return true
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
return logging.socket
|
||
|
|