Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
GrimmSpector

Error Logging...

Question

Posted

I'd like to do error/function logging, and I'd like to do it via binding the STDERR output to a filestream instead of the GPU. I'm not familiar enough with lua yet to do it. Can anyone help me with this? Thanks.

7 answers to this question

Recommended Posts

  • 0
Posted

You probably just want to use

io.stderr:write() 

 for that

 

Not quite what I'm asking. I'm well aware of the io stream and method. However that logs when running a program to a temporary file, that I don't get to keep handy, and to the console.

 

I don't want it to print to the GPU at all. I ONLY want it to go to a file, and I don't want it to go to a temporary file, I want to ecapsulate extra logging information and all error debug information out to a file of my choosing. Ideally with a bit of parsing to make it more readable. I can't figure out how to adjust the stream to

a) not go to the GPU

B) go to a file of my own choosing

 

Seems to be a weird thing to do in lua?

  • 0
Posted

Simple function injection

function io.stderr:write(str)
	logFile = filesystem.open(self.path, "a")
	logFile:write(str.."\n")
	logFile:close()
	return self
end

Either replace self.path with a path or leave it as is and change io.stderr.path to change the path of the next error log writes.

  • 0
Posted

Simple function injection

function io.stderr:write(str)
	logFile = filesystem.open(self.path, "a")
	logFile:write(str.."\n")
	logFile:close()
	return self
end

Either replace self.path with a path or leave it as is and change io.stderr.path to change the path of the next error log writes.

 

Perfect, thanks!

  • 0
Posted

Simple function injection

function io.stderr:write(str)
	logFile = filesystem.open(self.path, "a")
	logFile:write(str.."\n")
	logFile:close()
	return self
end

Either replace self.path with a path or leave it as is and change io.stderr.path to change the path of the next error log writes.

 

Well...this crashes the OC hard...

"Unrecoverable Error"

controller.lua:50: attempt to index global 'logFile' (a nil value) 
  • 0
Posted

What did you set io.stderr.path to?

 

For verbose error logging try

oldStderr = io.stderr

function io.stderr:write(str)
	logFile, err = filesystem.open(self.path, "a")
        if not logFile then
            io.stderr = oldStderr
            error(err)
        end
	logFile:write(str.."\n")
	logFile:close()
	return self
end

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.