log4mongo / log4mongo-python

python logging handler for mongo database
http://log4mongo.org
Other
111 stars 37 forks source link

Can't get it work #13

Closed ErikvdVen closed 8 years ago

ErikvdVen commented 8 years ago

When using pymongo 2.6.3 according to the requirements.txt, I receive this error: Unable to connect to the database. command SON([('authenticate', 1), ('user', u'ads'), ('nonce', u'8607e5da456556b5'), ('key', u'd13b8199999884353743a93e7d739')]) failed: auth failed

But as soon as I upgrade to 3.0.3. the error disappears, but below code returns a None:

MONGOLAB_URI_PARSED = urlparse('mongodb://ads:pass888@ds055554.mongolab.com:41484/heroku_b985544')
    MONGOLAB_CONF_DICT = dict(
        host = MONGOLAB_URI_PARSED.hostname,
        port = MONGOLAB_URI_PARSED.port,
        database_name = MONGOLAB_URI_PARSED.path[1:],
        username = MONGOLAB_URI_PARSED.username,
        password = MONGOLAB_URI_PARSED.password
    )

    logger = logging.getLogger(name)

    logger.addHandler(MongoHandler(level=logging.DEBUG, collection='logs', **MONGOLAB_CONF_DICT))
    print logger.warning('test')

Can you help?

char0n commented 8 years ago

@oz123 do you have any idea ?

oz123 commented 8 years ago

@ErikvdVen it seems a correct behaviour to me. logger.warning is not returning anything. See the code here: https://hg.python.org/cpython/file/2.7/Lib/logging/__init__.py

What happens when you remove that print statement?

Do you see the warning 'test' in your collection?

As for the failed authentication. Does the code work on a collection or database without authentication with 2.6.3? Mongodb has done some changes regarding authentication, so I am not sure what the exactly is going on without further information.

ErikvdVen commented 8 years ago

Thank you for your responses!

I just figured out this morning another database, called "logs", was created and was filled with log records. They where created yesterday around 15:00, so then I had a configuration that worked.

After some trial and error I figured out this configuration worked!

def setup_logging_to_mongo(name):
    logger = logging.getLogger(name)

    logger.addHandler(MongoHandler(level='DEBUG'))
    logger.exception('test')

logger.warning('test') did not work, but after changing it to logger.exception('test') it did appear inside the mongodb database. So it seems like it still works, now I only need to figure out how to get it work on mongolab. But I guess that shouldn't be a problem :)

oz123 commented 8 years ago

@ErikvdVen how familiar are you with logging levels? The documentation is quite tricky. Make sure you understand what gets logged when. @char0n This ticket can be closed. Can you add me to the list of people who can close tickets please?

ErikvdVen commented 8 years ago

Well I guess I have to read the documentation again then :) I just use it a few weeks, for Python, and I only used the exception function so far to log errors. Mostly errors from the postgreSQL pipelines.

But it seems that the logger.warning() doesn't write anything to the mongodb collection and logger.exception() does. I just tried my first configuration on mongolab, only replaced logger.warning() with logger.exception() and it worked.

oz123 commented 8 years ago

logger.warning isn't writing anything because you didn't set the application logging level correctly. If you want logging.warning levels to appear you should set the level properly. Look at the test cases for examples.

ErikvdVen commented 8 years ago

Aha, that makes sense. I'll look at the test cases. Thanks for your help.

char0n commented 8 years ago

Can we close this issue ?

ErikvdVen commented 8 years ago

Yes you can close this issue

char0n commented 8 years ago

Fine, thanks.