Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Adds logging to /var/log/syslog using rsyslog #58

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion securedrop_proxy/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import logging
import os
import sys
import platform

from logging.handlers import TimedRotatingFileHandler
from logging.handlers import TimedRotatingFileHandler, SysLogHandler

from securedrop_proxy import main
from securedrop_proxy import proxy
Expand Down Expand Up @@ -83,7 +84,19 @@ def configure_logging() -> None:
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)

# For rsyslog handler
if platform.system() != "Linux": # pragma: no cover
syslog_file = "/var/run/syslog"
else:
syslog_file = "/dev/log"

sysloghandler = SysLogHandler(address=syslog_file)
sysloghandler.setFormatter(formatter)

# set up primary log
log = logging.getLogger()
log.setLevel(LOGLEVEL)
log.addHandler(handler)

# add the secondard logger
log.addHandler(sysloghandler)
18 changes: 18 additions & 0 deletions tests/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import io
import json
import os
import platform
import tempfile
import unittest.mock
from unittest.mock import patch

import vcr
from securedrop_proxy import entrypoint
Expand Down Expand Up @@ -46,6 +48,22 @@ def test_missing_config(self):
body["error"], "Configuration file does not exist at {}".format(config_path)
)

@patch("securedrop_proxy.entrypoint.logging")
@patch("securedrop_proxy.entrypoint.SysLogHandler")
@patch("securedrop_proxy.entrypoint.TimedRotatingFileHandler")
def test_configure_logging(self, mock_log_conf, mock_log_conf_sys, mock_logging):
with sdhome() as homedir:
mock_log_file = os.path.join(homedir, 'logs', 'proxy.log')
entrypoint.configure_logging()
mock_log_conf.assert_called_once_with(mock_log_file)
# For rsyslog handler
if platform.system() != "Linux": # pragma: no cover
syslog_file = "/var/run/syslog"
else:
syslog_file = "/dev/log"
mock_log_conf_sys.assert_called_once_with(address=syslog_file)
mock_logging.getLogger.assert_called_once_with()

def test_unwritable_log_folder(self):
"""
Tests a permission problem in `configure_logging`.
Expand Down