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

Commit

Permalink
Adds logging to /var/log/syslog using rsyslog
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed Jan 13, 2020
1 parent 21c2963 commit 8522240
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,7 @@ Notice that you receive a `400` response from the proxy:

$ echo '[INVALID' | /usr/lib/qubes/qrexec-client-vm securedrop-proxy securedrop.Proxy
{"body": "{\"error\": \"Invalid JSON in request\"}", "version": "0.1.1", "status": 400, "headers": {"Content-Type": "application/json"}}

#### Logs

Logs can be found in the `/var/log/syslog` file.
11 changes: 2 additions & 9 deletions securedrop_proxy/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import sys

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

from securedrop_proxy import main
from securedrop_proxy import proxy
Expand Down Expand Up @@ -65,21 +65,14 @@ def configure_logging() -> None:
"""
All logging related settings are set up by this function.
"""
home = os.getenv("SECUREDROP_HOME", DEFAULT_HOME)
log_folder = os.path.join(home, "logs")
if not os.path.exists(log_folder):
os.makedirs(log_folder)

log_file = os.path.join(home, "logs", "proxy.log")

# set logging format
log_fmt = (
"%(asctime)s - %(name)s:%(lineno)d(%(funcName)s) %(levelname)s: %(message)s"
)
formatter = logging.Formatter(log_fmt)

# define log handlers such as for rotating log files
handler = TimedRotatingFileHandler(log_file)
handler = SysLogHandler(address="/dev/log")
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)

Expand Down
20 changes: 0 additions & 20 deletions tests/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,6 @@ def test_missing_config(self):
body["error"], "Configuration file does not exist at {}".format(config_path)
)

def test_unwritable_log_folder(self):
"""
Tests a permission problem in `configure_logging`.
"""
output = None
with sdhome() as home:
os.chmod(home, 0o0444)
with unittest.mock.patch(
"sys.stdout", new_callable=io.StringIO
) as mock_stdout:
with self.assertRaises(SystemExit):
entrypoint.start()
output = mock_stdout.getvalue()
os.chmod(home, 0o0700)

response = json.loads(output)
self.assertEqual(response["status"], http.HTTPStatus.INTERNAL_SERVER_ERROR)
body = json.loads(response["body"])
self.assertIn("Permission denied: ", body["error"])

def test_wrong_number_of_arguments(self):
with sdhome() as home: # noqa: F841
with unittest.mock.patch(
Expand Down

0 comments on commit 8522240

Please sign in to comment.