use django logging from outside

82 views
Skip to first unread message

Det S. Pillner

unread,
Jan 20, 2016, 5:35:48 AM1/20/16
to Django users
Hi all,

I work on a django project. I use very heavy logging in this project. Some parts of code needs to start over a cron job outside of the django project. In this - I call it modules - I try to use my existing django logging config. Code execution displays no errors bud there are no logging entries.

Can somebody help to fix my problem?

James Schneider

unread,
Jan 23, 2016, 5:38:31 AM1/23/16
to django...@googlegroups.com

Are you bring in your entire Django environment via a django.setup() call, or are you simply trying to import the logging configuration that is being used by your Django project?

Without some explanation of what you've tried, I don't think we have enough information to help.

-James

Det S. Pillner

unread,
Feb 11, 2016, 7:32:51 AM2/11/16
to Django users
Oh Sorry for the late answer. Holiday.

Here is the content of my bash script to call one of the modules that I use from outside of Django:

  
# django/python settings
PYTHONPATH="${PYTHONPATH}:/srv/wpkg_webtools/"
export PYTHONPATH
export DJANGO_SETTINGS_MODULE=wpkg_webtools.settings.privat

# call python part (django module)
python /srv/wpkg_webtools/wpkg/modules/fill.py $1

This script is called from a cron job and find.

In my module I use this:

import os
import os.path
import glob
import sys
import xml.etree.ElementTree as eTree
import logging
import logging.config
import logging.handlers
from time import gmtime, strftime

from django.db import connection

from wpkg.models.wpkg import *

logger
= logging.getLogger('imp')  # global logger for fill

I does not get a error message. That means: Python can find all things. And below: a part from settings.py:

'imp': {
   
'handlers': ['import'],
   
'level': 'DEBUG',
},

This logger is used by other parts IN django also.

Thanks for your reaction. I will try django.setup() in the head of my module.

Det S. Pillner

unread,
Feb 15, 2016, 8:48:38 AM2/15/16
to Django users
Tested . Works great.

No I use django.setup() in __main__ section and get logger in function. Many thanks. 
Reply all
Reply to author
Forward
0 new messages