diff options
author | Matthew Summers <matthew.summers@liquidustech.com> | 2009-10-22 15:47:55 -0500 |
---|---|---|
committer | Matthew Summers <matthew.summers@liquidustech.com> | 2009-10-22 15:47:55 -0500 |
commit | a8312722196cd66060841bc59f41520d29702d39 (patch) | |
tree | fda70ee969423e0f8f944e7ad7478530e209c059 | |
parent | Intial commit. (diff) | |
download | gentoo-ads-a8312722196cd66060841bc59f41520d29702d39.tar.gz gentoo-ads-a8312722196cd66060841bc59f41520d29702d39.tar.bz2 gentoo-ads-a8312722196cd66060841bc59f41520d29702d39.zip |
Created impressions logging using python logging module, thanks to Darren Wynne of
Liquidus Tech for the assist with that.
Added new settings related to the above
Added to the README to reflect the changes
Updated the TODO
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | TODO | 9 | ||||
-rw-r--r-- | gentoo_ads/ads/views.py | 7 | ||||
-rw-r--r-- | gentoo_ads/example_settings.py | 8 | ||||
-rw-r--r-- | gentoo_ads/logging_setup.py | 58 |
5 files changed, 81 insertions, 3 deletions
@@ -1,5 +1,5 @@ gentoo-ads -created by Matthew Summers and Richard Anderson of Liquidus Tech, LLC +created by Matthew Summers, Richard Anderson and Darren Wynne of Liquidus Tech, LLC this is an ads (automated display system) written in python and using the django web framework @@ -4,14 +4,19 @@ gentoo-ads show how to serve the static media via dev server create demo images -implement impression counter + +Below is complete using python's logging module for performance & simplicity +[[ implement impression counter needs design decision what is the desired output for analysis why not use apache logs? +]] implement serialized POST to collect clickthru and related JS design decision needed what info from the REQUEST object do we want? -Something else maybe? +This is for SysAdmins by SysAdmins so we will not make a dashboard unless someone wants it really bad. +[[ Something else maybe? A nice little analytics dashboard ... that could be nice. +]]
\ No newline at end of file diff --git a/gentoo_ads/ads/views.py b/gentoo_ads/ads/views.py index c98968d..6bba316 100644 --- a/gentoo_ads/ads/views.py +++ b/gentoo_ads/ads/views.py @@ -4,6 +4,7 @@ from django.shortcuts import render_to_response from django.conf import settings from random import randint +import logging def serve_ads(request): sample = _weighted_random_sample(settings.ADS_STRUCT) @@ -27,4 +28,10 @@ def _weighted_random_sample(ads): ads = ads[:ad_i] + ads[ad_i + 1:] break + log_data = { + 'site_name': settings.AD_LOG_PREFIX, + } + + ads_log_data_message = ','.join([a['name'] for a in ads_out]) + logging.info(ads_log_data_message, extra=log_data) return ads_out
\ No newline at end of file diff --git a/gentoo_ads/example_settings.py b/gentoo_ads/example_settings.py index f76c474..60cb68d 100644 --- a/gentoo_ads/example_settings.py +++ b/gentoo_ads/example_settings.py @@ -13,6 +13,14 @@ import os ## please note, in general the ads.py file should live outside the webroot. CONFIG_PATH = '/some/path/towards/the/file/gentoo-ads/example_ads.py' +## Put in an identifying string like gentoo-ads +## This facilitates filtering with syslog +AD_LOG_PREFIX = 'example-domain-ads' + +## PLEASE NOTE: You need to setup two variables in logging_setup.py, namely LOGGING_DEBUG and SYS_LOG_ADDRESS +## IF LOGGING_DEBUG = True we log to both the console (for debugging) and syslog +## SYS_LOG_ADDRESS is simply the log file you wish to use, in general and since we want to use the SysLogHandler, we desire to log to /dev/log + ## nifty, facilitates use of advertiser dictionary ## loads a python module living somwhere on the machine ## though if it finds a good .pyc|o it will use it first diff --git a/gentoo_ads/logging_setup.py b/gentoo_ads/logging_setup.py new file mode 100644 index 0000000..a8ceef0 --- /dev/null +++ b/gentoo_ads/logging_setup.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +import logging + +from logging.handlers import SysLogHandler + +LOGGING_DEBUG = True + +SYS_LOG_ADDRESS = '/dev/log' + +if not hasattr(logging, "set_up_done"): + logging.set_up_done=False + +def setup_logging(): + + if logging.set_up_done: + return + + + logger = logging.getLogger() + if LOGGING_DEBUG: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + formatter = logging.Formatter("[%(site_name)s] %(asctime)s %(levelname)s %(message)s") + + # test console logger + if LOGGING_DEBUG: + handler = logging.StreamHandler() + handler.setLevel(logging.DEBUG) + handler.setFormatter(formatter) + logger.addHandler(handler) + + # SysLogHandler + SysLogAddress = SYS_LOG_ADDRESS + if SysLogAddress is not None: + handler = SysLogHandler(SysLogAddress) + handler.setLevel(logging.INFO) + handler.setFormatter(formatter) + logger.addHandler(handler) + + ######################### + # LOGGING LEVELS + # * indicates a custom level + # + # CRITICAL 50 + # ERROR 40 + # WARNING 30 + # INFO 20 + # DEBUG 10 + # NOTSET 0 + # + + + + logging.set_up_done=True + +setup_logging() |