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

Error Logging...

Question

7 answers to this question

Recommended Posts

  • 0

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?

Link to post
Share on other sites
  • 0

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.

Link to post
Share on other sites
  • 0

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!

Link to post
Share on other sites
  • 0

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) 
Link to post
Share on other sites
  • 0

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
Link to post
Share on other sites

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.