Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #218 from alphagov/add-app-name
Browse files Browse the repository at this point in the history
Add app name as a tag to json logs
  • Loading branch information
nickgravgaard committed Jan 6, 2014
2 parents fdd77f6 + 4aa95fd commit 9517851
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions backdrop/core/log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def get_log_file_handler(path, log_level=logging.DEBUG):
return handler


def get_json_log_handler(path):
def get_json_log_handler(path, app_name):
handler = FileHandler(path)
formatter = LogstashFormatter()
formatter.defaults['@tags'] = ['application']
formatter.defaults['@tags'] = ['application', app_name]
handler.setFormatter(formatter)
return handler

Expand All @@ -26,7 +26,7 @@ def set_up_logging(app, env):
get_log_file_handler("log/%s.log" % env, log_level)
)
app.logger.addHandler(
get_json_log_handler("log/%s.log.json" % env)
get_json_log_handler("log/%s.log.json" % env, app.name)
)
app.logger.setLevel(log_level)
app.logger.info("{} logging started".format(app.name))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pytz==2013b
rauth==0.5.5
statsd==2.0.3
xlrd==0.9.2
-e git+https://github.com/alphagov/python-logstash-formatter.git@fix-docstring#egg=logstash_formatter
logstash_formatter==0.5.7
2 changes: 1 addition & 1 deletion tests/core/test_json_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_json_log_written_when_logger_called(self):
}))

assert_that(data, has_entries({
'@tags': ['application']
'@tags': ['application', 'json_test_app']
}))

# Only remove file if assertion passes
Expand Down

0 comments on commit 9517851

Please sign in to comment.