mirror of
https://github.com/kepler155c/opus
synced 2025-10-19 09:47:39 +00:00
cloud edit + logger removal
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
local Logger = {
|
||||
fn = function() end,
|
||||
filteredEvents = { },
|
||||
}
|
||||
|
||||
function Logger.setLogger(fn)
|
||||
Logger.fn = fn
|
||||
end
|
||||
|
||||
function Logger.disable()
|
||||
Logger.setLogger(function() end)
|
||||
end
|
||||
|
||||
function Logger.setDaemonLogging()
|
||||
Logger.setLogger(function (text)
|
||||
os.queueEvent('log', { text = text })
|
||||
end)
|
||||
end
|
||||
|
||||
function Logger.setMonitorLogging()
|
||||
local debugMon = device.monitor
|
||||
|
||||
if not debugMon then
|
||||
debugMon.setTextScale(.5)
|
||||
debugMon.clear()
|
||||
debugMon.setCursorPos(1, 1)
|
||||
Logger.setLogger(function(text)
|
||||
debugMon.write(text)
|
||||
debugMon.scroll(-1)
|
||||
debugMon.setCursorPos(1, 1)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function Logger.setScreenLogging()
|
||||
Logger.setLogger(function(text)
|
||||
local x, y = term.getCursorPos()
|
||||
if x ~= 1 then
|
||||
local sx, sy = term.getSize()
|
||||
term.setCursorPos(1, sy)
|
||||
--term.scroll(1)
|
||||
end
|
||||
print(text)
|
||||
end)
|
||||
end
|
||||
|
||||
function Logger.setWirelessLogging()
|
||||
if device.wireless_modem then
|
||||
Logger.filter('modem_message')
|
||||
Logger.filter('modem_receive')
|
||||
Logger.filter('rednet_message')
|
||||
Logger.setLogger(function(text)
|
||||
device.wireless_modem.transmit(59998, os.getComputerID(), {
|
||||
type = 'log', contents = text
|
||||
})
|
||||
end)
|
||||
Logger.debug('Logging enabled')
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function Logger.setFileLogging(fileName)
|
||||
fs.delete(fileName)
|
||||
Logger.setLogger(function (text)
|
||||
local logFile
|
||||
|
||||
local mode = 'w'
|
||||
if fs.exists(fileName) then
|
||||
mode = 'a'
|
||||
end
|
||||
local file = io.open(fileName, mode)
|
||||
if file then
|
||||
file:write(text)
|
||||
file:write('\n')
|
||||
file:close()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Logger.log(category, value, ...)
|
||||
if Logger.filteredEvents[category] then
|
||||
return
|
||||
end
|
||||
|
||||
if type(value) == 'table' then
|
||||
local str
|
||||
for k,v in pairs(value) do
|
||||
if not str then
|
||||
str = '{ '
|
||||
else
|
||||
str = str .. ', '
|
||||
end
|
||||
str = str .. k .. '=' .. tostring(v)
|
||||
end
|
||||
if str then
|
||||
value = str .. ' }'
|
||||
else
|
||||
value = '{ }'
|
||||
end
|
||||
elseif type(value) == 'string' then
|
||||
local args = { ... }
|
||||
if #args > 0 then
|
||||
value = string.format(value, unpack(args))
|
||||
end
|
||||
else
|
||||
value = tostring(value)
|
||||
end
|
||||
Logger.fn(category .. ': ' .. value)
|
||||
end
|
||||
|
||||
function Logger.debug(value, ...)
|
||||
Logger.log('debug', value, ...)
|
||||
end
|
||||
|
||||
function Logger.logNestedTable(t, indent)
|
||||
for _,v in ipairs(t) do
|
||||
if type(v) == 'table' then
|
||||
log('table')
|
||||
logNestedTable(v) --, indent+1)
|
||||
else
|
||||
log(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Logger.filter( ...)
|
||||
local events = { ... }
|
||||
for _,event in pairs(events) do
|
||||
Logger.filteredEvents[event] = true
|
||||
end
|
||||
end
|
||||
|
||||
return Logger
|
@@ -1,5 +1,4 @@
|
||||
local Crypto = require('crypto')
|
||||
local Logger = require('logger')
|
||||
local Security = require('security')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -15,7 +14,6 @@ function socketClass:read(timeout)
|
||||
end
|
||||
|
||||
if not self.connected then
|
||||
Logger.log('socket', 'read: No connection')
|
||||
return
|
||||
end
|
||||
|
||||
@@ -64,7 +62,6 @@ end
|
||||
|
||||
function socketClass:close()
|
||||
if self.connected then
|
||||
Logger.log('socket', 'closing socket ' .. self.sport)
|
||||
self.transmit(self.dport, self.dhost, {
|
||||
type = 'DISC',
|
||||
})
|
||||
@@ -113,7 +110,6 @@ function Socket.connect(host, port)
|
||||
|
||||
local socket = newSocket(host == os.getComputerID())
|
||||
socket.dhost = tonumber(host)
|
||||
Logger.log('socket', 'connecting to ' .. port)
|
||||
|
||||
socket.transmit(port, socket.sport, {
|
||||
type = 'OPEN',
|
||||
@@ -138,8 +134,8 @@ function Socket.connect(host, port)
|
||||
|
||||
socket.dport = dport
|
||||
socket.connected = true
|
||||
Logger.log('socket', 'connection established to %d %d->%d',
|
||||
host, socket.sport, socket.dport)
|
||||
-- Logger.log('socket', 'connection established to %d %d->%d',
|
||||
-- host, socket.sport, socket.dport)
|
||||
|
||||
_G.transport.open(socket)
|
||||
|
||||
@@ -179,7 +175,7 @@ end
|
||||
|
||||
function Socket.server(port)
|
||||
device.wireless_modem.open(port)
|
||||
Logger.log('socket', 'Waiting for connections on port ' .. port)
|
||||
-- Logger.log('socket', 'Waiting for connections on port ' .. port)
|
||||
|
||||
while true do
|
||||
local _, _, sport, dport, msg = os.pullEvent('modem_message')
|
||||
@@ -203,7 +199,7 @@ function Socket.server(port)
|
||||
dhost = socket.dhost,
|
||||
shost = socket.shost,
|
||||
})
|
||||
Logger.log('socket', 'Connection established %d->%d', socket.sport, socket.dport)
|
||||
-- Logger.log('socket', 'Connection established %d->%d', socket.sport, socket.dport)
|
||||
|
||||
_G.transport.open(socket)
|
||||
return socket
|
||||
|
Reference in New Issue
Block a user