Skip to content

Commit

Permalink
Added 'max_keep' paramter
Browse files Browse the repository at this point in the history
  • Loading branch information
John Furr authored and John Furr committed Sep 25, 2016
1 parent 690c6dc commit 06476f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,6 +1,10 @@
Change Log
==========

v0.7.4
------
* Added base paramter 'max_keep' that is used for embedded documents to determine how many records to keep

v0.7.3
------
* Moved all test logging to settings.LOGGING
Expand Down
8 changes: 4 additions & 4 deletions mongolog/handlers.py
Expand Up @@ -62,7 +62,7 @@ def get_mongolog_handler(logger_name=None):
break

if not handler:
raise ValueError("No BaseMongoLogHandler could be found. Did you add on to you logging config?")
raise ValueError("No BaseMongoLogHandler could be found. Did you add on to youy logging config?")
return handler


Expand All @@ -71,7 +71,7 @@ class BaseMongoLogHandler(Handler):
REFERENCE = 'reference'
EMBEDDED = 'embedded'

def __init__(self, level=NOTSET, connection=None, w=1, j=False, verbose=None, time_zone="local", record_type="embedded", *args, **kwargs): # noqa
def __init__(self, level=NOTSET, connection=None, w=1, j=False, verbose=None, time_zone="local", record_type="embedded", max_keep=25, *args, **kwargs): # noqa
super(BaseMongoLogHandler, self).__init__(level)
self.connection = connection

Expand All @@ -83,7 +83,7 @@ def __init__(self, level=NOTSET, connection=None, w=1, j=False, verbose=None, ti
self.record_type = record_type

# number of dates to keep in embedded document
self.num_dates = 25
self.max_keep = max_keep

# The write concern
self.w = w
Expand Down Expand Up @@ -286,7 +286,7 @@ def insert_embedded(self, log_record):
"$push": {
'dates': {
'$each': [log_record['time']],
"$slice": -self.num_dates # only keep the last n entries
"$slice": -self.max_keep # only keep the last n entries
}
},
# Keep a counter of the number of times we see this record
Expand Down
4 changes: 3 additions & 1 deletion settings/settings.py
Expand Up @@ -34,6 +34,8 @@
# Uncomment section to play with SimpleMongoLogHandler
'class': 'mongolog.SimpleMongoLogHandler',
'connection': 'mongodb://localhost:27017',
'max_keep': 5,
'record_type': 'embedded'
},
'http': {
'level': 'DEBUG',
Expand Down Expand Up @@ -129,7 +131,7 @@
'class': 'mongolog.HttpLogHandler',
# Interesting Note: requests 2.8.1 will turn this into a GET if it's missing a trailing slash
# We automagically add the trailing slash
'client_auth': 'http://192.168.33.51/4e487f07a84011e5a3403c15c2bcc424',
'client_auth': 'http://192.168.33.51/4e487f07a84011e5a3403c15c2bcc424/',
'verbose': TEST_VERBOSITY,
'timeout': 1,
},
Expand Down

0 comments on commit 06476f1

Please sign in to comment.