Skip to content

Commit

Permalink
add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fuji246 committed Mar 17, 2013
1 parent b339761 commit 26bf3b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions bbb_django/bbb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pytz

def parse(response):
settings.LOGGER.debug(response)
try:
xml = ET.XML(response)
code = xml.find('returncode').text
Expand Down
24 changes: 24 additions & 0 deletions bbb_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@

AUTH_PROFILE_MODULE = 'bbb.UserProfile'

import logging
import logging.handlers
import os.path
here = lambda x: os.path.join(os.path.abspath(os.path.dirname(__file__)), x)

LOG_DIR = here('log')
LOG_FILE_SIZE = 50*1024*1024
LOG_BAKUP_CNT = 10

if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR)
LOG_FILENAME = LOG_DIR + os.sep +'bbb_django.log'
LOGGER = logging.getLogger('bbb_django')
if DEBUG:
LOGGER.setLevel(logging.DEBUG)
else:
LOGGER.setLevel(logging.INFO)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=LOG_FILE_SIZE, backupCount=LOG_BAKUP_CNT)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')#("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
LOGGER.addHandler(handler)

LOGGER.debug("log init ok: %s"%LOG_DIR)

## Load our local_settings
try:
from bbb.local_settings import *
Expand Down

0 comments on commit 26bf3b8

Please sign in to comment.