ReviewBoard log activation causes Error 500 on Windows

Review Request #6056 — Created July 4, 2014 and submitted

Information

Djblets

Reviewers

After loging in as an admin and enabling the logging with debug and set the path to something like C:\Logs, you get an Error 500. Checking the logs I found this error trace
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868]
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] 'module' object has no attribute 'FileHandler'
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] Traceback (most recent call last):
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\django\django\core\handlers\base.py", line 112, in get_response
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] response = wrapped_callback(request, callback_args, callback_kwargs)
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\django\django\utils\decorators.py", line 99, in _wrapped_view
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] response = view_func(request,
args, kwargs)
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\django\django\contrib\admin\views\decorators.py", line 17, in _checklogin
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] return view_func(request, *args,
kwargs)
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\reviewboard\Lib\site-packages\ReviewBoard-2.0.2-py2.7.egg\reviewboard\admin\views.py", line 93, in site_settings
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] 'root_path': settings.SITE_ROOT + "admin/db/"
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\django\django\utils\decorators.py", line 99, in _wrapped_view
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] response = view_func(request, args, kwargs)
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\django\django\contrib\admin\views\decorators.py", line 17, in _checklogin
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] return view_func(request,
args, **kwargs)
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\python\lib\site-packages\djblets-0.8.4-py2.7.egg\djblets\siteconfig\views.py", line 52, in site_settings
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] form.save()
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\apps\reviewboard\Lib\site-packages\ReviewBoard-2.0.2-py2.7.egg\reviewboard\admin\forms.py", line 711, in save
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] restart_logging()
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\python\lib\site-packages\djblets-0.8.4-py2.7.egg\djblets\log\init.py", line 237, in restart_logging
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] init_logging()
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] File "C:\Bitnami\reviewboard-2.0.2-0\python\lib\site-packages\djblets-0.8.4-py2.7.egg\djblets\log\init.py", line 161, in init_logging
[Thu Jul 03 17:58:58.005859 2014] [:error] [pid 2840:tid 868] handler = logging.handlers.FileHandler(log_path)
[Thu Jul 03 17:58:58.006835 2014] [:error] [pid 2840:tid 868] AttributeError: 'module' object has no attribute 'FileHandler'

Checking the log module in Djblets, I saw this

try:
if sys.platform == 'win32':
handler = logging.handlers.FileHandler(log_path)
else:
handler = logging.handlers.WatchedFileHandler(log_path)

If you take a look at the Python documentation (https://docs.python.org/2/library/logging.handlers.html) it says

"Note that three of the handlers (StreamHandler, FileHandler and NullHandler) are actually defined in the logging module itself". So you need to change the handler in Windows to this

if sys.platform == 'win32':
handler = logging.FileHandler(log_path)

And it will work.


 
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/log/__init__.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/log/__init__.py
    
    
  2. 
      
CA
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.8.x (fd08e05)
chipx86
  1. Ship It!

  2.