Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --The Log API 1.1
- runningProgram = "test"
- -- open: opens the file
- function openLog(name)
- h = fs.open("logs/"..name..".log", "a")
- end
- function closeLog()
- h.close()
- end
- --function setRunningProgram(name)
- -- runningProgram = name
- --end
- function generateLog() --will create the Dir "log" in the root and create a .log file based on the running program (if if is not already there)
- if not fs.exists("logs") then
- fs.mkDir("logs")
- end
- if runningProgram == nil then
- error("program not specified")
- end
- h = fs.open("logs/"..runningProgram..".log", "a")
- h.writeLine("--- The "..runningProgram.." event log ---")
- h.writeLine(" ")
- h.close()
- end
- function addEntry(type, str)
- local time = round(os.time(), 2)
- local day = os.day()
- h.writeLine("["..day.."]".."["..time.."]".."["..type.."] | #"..str)
- end
- -- start/end add start/end messages
- function startLog()
- open = true
- local time = os.time()
- local day = os.day()
- h.writeLine("["..day.."]".."["..time.."] | #STARTING LOG")
- end
- function endLog()
- open = false
- local time = os.time()
- local day = os.day()
- h.writeLine("["..day.."]".."["..time.."] | #ENDING LOG")
- end
- -- a function you cant access ;P
- local function round(num, idp)
- local mult = 10 ^ (idp or 0)
- return (math.floor(num * mult + 0.5) / mult)
- end
- --will print the desired log
- function printLog(log, side, fromLn, toLn)
- if open == true then
- error("Log must be ended before printing")
- end
- if not fs.exists( "logs/"..log..".log") then
- error("Log does not exist")
- end
- h = fs.open("logs/"..log..".log", "r")
- page = {}
- while h.readLine() ~= nil do
- local ln = h.readLine()
- table.insert(page, ln)
- end
- p = peripheral.wrap(side)
- p.newPage()
- local paper = p.getPaperLevel()
- local ink = p.getInkLevel()
- local w, h = p.getPageSize()
- local doc = {}
- for i = fromLn, toLn do
- table.insert(doc, page[i])
- end
- local length = 0
- for i = 1, #doc do
- length = length + #doc[i]
- end
- local size = w*h
- local pages = round(length/size, 0)
- if pages > paper then
- error("not enough paper")
- end
- if pages > ink then
- error("not enough ink")
- end
- for i = 1, pages do
- p.newPage()
- p.setPageTitle(log.." page:"..i)
- for indx = 1, size do
- p.write(doc[indx])
- end
- p.endPage()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement