Forums

Is there a way to archive or clear "<user>.pythonanywhere.com.error.log"?

Ugh. I logged a really long line to it, now its a royal pain in the **S to scroll horizontally.

Is there a way to archive it, or clear it?

Or when does it roll over on its own?

You can just delete it if you want to clear it. It's in /var/log/. If you want to archive it, just use Bash to move it aside.

That worked, thanks!

Kinda scared me when no more messages were logged...

I eventually figured out to hit the "Reload" web app button. I guess its the only quick way to create the file....

Then messages started flowing in, whew!

I was worried I broke the Internet for a minute there.....

Happy Friday!

How exactly?

I tried:

14:02 /var/log $ rm coolroar.pythonanywhere.com.error.log

but got:

rm: cannot remove ‘coolroar.pythonanywhere.com.error.log’: Permission denied

Thanks, Joe

the error log should get rotated every day, so it'll clear down all by itself by tomorrow... Alternatively, although you can't delete it, you can write to it. So you can open it in the editor, do a ctrl+a then delete then save, or alternatively:

echo '' > /var/log/mydomain.name.com.error.log

Oh. Ah... Thanks for the quick lesson, heh.

For some reason, I got 'permission denied'. How do I clear my error log?

Did you do the echo to a log file that actually existed when you ran the command?

Same permission denied problem here

What permission denied problem? What are you trying to do to what file?

I’m trying to delete it from the UI, but it just doesn’t have a trash icon next to it like usual files do.

You can overwrite the content of the log file with empty or use our helper script pa_delete_webapp_logs.py to remove logs: See https://github.com/pythonanywhere/helper_scripts#usage

As @fji said, We can not delete or remove logs files. But we have have write permissions for all log files. Just be creative. Write a simple Python code (.py file) to re-write* the logs.

Here is an Example. I wanted to clear "Error logs".

import os
from datetime import datetime
try:
    os.system('rmdir /var/log/')
except Exception as e:
    print("An error occured: "+str(e))
    print("But don't worry... We are trying different methods...")
    del e

try:
    f = open("/var/log/YourUserName.pythonanywhere.com.error.log", "w")
    time = datetime.now()
    msg = "Successfully deleted all error logs on "+str(time)+"\n"
    f.write(msg)
    f.close()
    del f
    f = open("/var/log/YourUserName.pythonanywhere.com.error.log", "r")
    print(f.read())
    del f
except Exception as e:
    print("An error occured: "+str(e)+"\n")
    print("Sorry! We couldn't delete or clear error Log file. :(")

If you want to clear Error logs, Just copy and paste above code in a new Python file (*.py file) and save it. [Please note that, you must replace "YourUserName" using your Pythonanywhere username before saving it.] After saving, open a Bash terminal in the folder which you saved the above code as a python file. Then run the python file. Just check the Error logs file....!

Here are some Screenshots. ⇓

Created a new python file named "Clearlogs.py" Copied the python code and replaced the "YourUserName" Ran the Python code using Bash console/ Terminal All Error logs gone

Note: If you want to clear other two log files, read above comments and just be creative.