Skip to content

Commit

Permalink
Set up logging
Browse files Browse the repository at this point in the history
Set up a logger and configure logging on AWS.

For:
#11
  • Loading branch information
liammulh committed Mar 28, 2024
1 parent 9eb61b2 commit afb1c29
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .ebextensions/logs.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This should stream our logs to AWS CloudWatch.
option_settings:
aws:elasticbeanstalk:cloudwatch:logs:
StreamLogs: true
DeleteOnTerminate: false
RetentionInDays: 60
7 changes: 7 additions & 0 deletions doc/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Logs

When running locally, logs are written to stdout. When running on AWS,
logs can be viewed in CloudWatch. To view the logs, navigate to the
CloudWatch web console, then in the side bar click the link to the log
groups page. Then look for the `web.stdout.log` log group. Then click
the appropriate log stream (probably the most recent one).
8 changes: 8 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
"""

# Built-in libraries:
import logging
import os
import subprocess

# Third-party dependencies:
from flask import Flask

# Configure logger.
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = Flask(__name__)


@app.route("/")
def hello_world():
"""A cheeky hello world route."""
logger.info("User accessed /")
return "<p>Look on my Affiliations Service, ye Mighty, and despair!</p>"


@app.route("/sha")
def current_git_sha():
"""Displays current Git SHA."""
logger.info("User accessed /sha")
command = ["git", "rev-parse", "HEAD"]
output = subprocess.run(command, check=False, capture_output=True).stdout.decode(
"utf-8"
Expand All @@ -34,4 +41,5 @@ def current_git_sha():
@app.route("/env")
def display_env_var():
"""Displays environment variable for testing purposes."""
logger.info("User accessed /env")
return os.environ.get("SOME_VAR")

0 comments on commit afb1c29

Please sign in to comment.