Advertisement
Guest User

log

a guest
Mar 14th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. --The Log API 1.1
  2. runningProgram = "test"
  3.  
  4. function openLog(name)
  5.     h = fs.open("logs/"..name..".log", "a")
  6. end
  7.  
  8. function closeLog()
  9.     h.close()
  10. end
  11.  
  12. --function setRunningProgram(name)
  13. --  runningProgram = name
  14. --end
  15.  
  16. 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)
  17.  
  18.     if not fs.exists("log") then
  19.         fs.mkDir("log")
  20.     end
  21.    
  22.     if runningProgram == nil then
  23.         error("program not specified")
  24.     end
  25.  
  26.         h = fs.open("logs/"..runningProgram..".log", "a")
  27.         h.writeLine("--- The "..runningProgram.." event log ---")
  28.         h.writeLine(" ")
  29.         h.close()
  30. end
  31.    
  32.  
  33. function addEntry(type, str)
  34.     local time = os.time()
  35.     local day = os.day()
  36.     h.writeLine("["..day.."]".."["..time.."]".."["..type.."] | #"..str)
  37. end
  38.  
  39. function startLog()
  40.     open = true
  41.     local time = os.time()
  42.     local day = os.day()
  43.     openLog()
  44.     h.writeLine("["..day.."]".."["..time.."] | #STARTING LOG")
  45. end
  46.  
  47. function endLog()
  48.     open = false
  49.     local time = os.time()
  50.     local day = os.day()
  51.     h.writeLine("["..day.."]".."["..time.."] | #ENDING LOG")
  52.    
  53. end
  54.  
  55. function setPrinterSide(side)
  56.     printside = side
  57. end
  58.  
  59. function printLog(log, fromLn, copies)
  60.  
  61.     if open == true then
  62.         error("Log must be ended before printing")
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement