This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from alphagov/logstash_json
Add json log formatter
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ assets/* | |
.coverage | ||
build | ||
coverage.xml | ||
*.log | ||
*.log* | ||
nosetests.xml | ||
pep8.out | ||
tmp/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from hamcrest import assert_that, has_entries | ||
import os | ||
import logging | ||
import json | ||
from backdrop.core import log_handler | ||
import unittest | ||
from flask import Flask | ||
|
||
|
||
class TestJsonLogging(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.app = Flask('json_test_app') | ||
self.logger = self.app.logger | ||
self.app.config['LOG_LEVEL'] = logging.DEBUG | ||
|
||
def test_json_log_written_when_logger_called(self): | ||
|
||
log_handler.set_up_logging(self.app, 'json_test', 'json_test') | ||
self.logger.info('Writing out JSON formatted logs m8') | ||
|
||
with open('log/json_test.log.json') as log_file: | ||
data = json.loads(log_file.readlines()[-1]) | ||
|
||
assert_that(data, has_entries({ | ||
'@message': 'Writing out JSON formatted logs m8' | ||
})) | ||
|
||
# Only remove file if assertion passes | ||
os.remove('log/json_test.log.json') |