Skip to content

Commit

Permalink
import warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Furr committed Jan 17, 2019
1 parent bde6034 commit 50fe43a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mongolog/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ def __init__(self, *args, **kwargs):

class LogConfigError(ValueError):
pass


class UnsupportedVersionError(ValueError):
pass
10 changes: 9 additions & 1 deletion mongolog/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from logging import Handler, NOTSET
from datetime import datetime as dt
import sys
import warnings

try:
from cStringIO import StringIO # noqa
except ImportError:
Expand All @@ -20,7 +22,10 @@
from pymongo.collection import ReturnDocument

from mongolog.models import LogRecord
from mongolog.exceptions import MissingConnectionError
from mongolog.exceptions import (
MissingConnectionError,
UnsupportedVersionError
)

logger = logging.getLogger('')
console = logging.getLogger('mongolog-int')
Expand Down Expand Up @@ -302,6 +307,9 @@ def insert_embedded(self, log_record):
self.mongolog.insert_one(log_record)
elif pymongo_version == 2:
self.mongolog.insert(log_record)
warnings.warn("pymongo version 2 is deprecated", DeprecationWarning)
else:
raise UnsupportedVersionError("mongolog currently on supports pymongo >= 2")
else:
# record has been seen before so we update the counter and push/pop
# the log record time. We keep the 'n' latest log record
Expand Down

0 comments on commit 50fe43a

Please sign in to comment.