3

I have written a python module that I'm using in my django app, so that it can be generalised. I have a django mangement function that calls this library.

Inside the library I've tried to use proper python logging. I have written a simple command line programme that calls the library and dumps logging data to stdout, and that works. However when this library is called from the django management command, there is logging output from the django management command, however there is no logging output from the library. It is as if there is no logging calls in the library.

I would like the logging output from the library and the django management command to appear on stdout. As if I just used print in both the django management command and the library.

Inside the django management command, I call this, so that all logging output goes to the terminal. I want logging output from this django management command and the library to go to the terminal.

import logging
logger = logging.getLogger(__name__)

class Command(BaseCommand):
    def handle(self, *args, **options):
        # ...
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
        ch.setFormatter(formatter)
        logger.addHandler(ch)
        logger.setLevel(logging.DEBUG)

Inside the library, I do logger = logging.getLogger(__name__)"at the root of the file as well.

I am new using the python logging framework (usually I just print ;)) So I might be making a simple mistake or asking for something that's delibrately impossible. This is Django 1.6.5, and python 2.7.6. My python library is pure python and is single threaded, it's all very simple.

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
  • You haven't made it clear what you are seeing. You say " there is logging output from the library. There is logging output from the django management command", which you say is what you want to happen: "I want logging output from this django management command and the library to go to the terminal" – Vinay Sajip Nov 26 '14 at 21:36
  • @VinaySajip I have updated the question. Sorry about that, this is what happens when you try to ask a question when half tired. – Amandasaurus Nov 27 '14 at 09:34

0 Answers0