1. Alexander Lyabah
  2. django-csvlog


Clone wiki

django-csvlog / Home


You are here, because you want a more advanced logger.


  1. Copy folder csvlog into your project folder
  2. Add string 'csvlog' in the INSTALLED_APPS in settings.py
  3. Add string 'csvlog.middleware.LogRequestInfo' at the end of array MIDDLEWARE_CLASSES in settings.py
  4. Add new var in settings.py CSVLOG_FILE = '/path_to_log/myapp.csv'

You can find ready setting.py in the root of this repository

Simple functions

listing of views.py

# coding: utf-8
from django.http import HttpResponse
from csvlog import glog
from django.contrib.auth.models import User
finlog = glog.get_log_func('inf','fin')
fin_money_log  = glog.get_log_func('inf',['fin','money'])
def somelog(request):
    #use object of logger as a simple function, for shorter logging
    glog('executin log by default name')
    #use different type of logs  
    glog.err('ERR, some error hapend')
    glog.imp('IMP, some important information')
    glog.inf('INF, some information')
    glog.log('LOG, some log')
    glog.trc('TRC, some trace')
    glog.dbg('DBG, debug information')
    #use utf-8
    glog.err(u'ERR, И чертовски важный русский текст')
    #use array for logging
    glog.inf(['here is array','first','second','tred','log is full, this will be removed'])
    #use predefined function for logging at the top of the module
    finlog('And one my log')
    finlog(['two el','one','tree'])
    fin_money_log('get 100$')
    return HttpResponse('OK')

def sometreelog(request):
    #you can use logs as tree
    #log in the first level
    glog.inf('inf in my tree')
    glog.inf('inf in my tree too')
    # open new level - "ntr" branch
    glog.alog('ntr',['New Tree NODE'])
    #log in the second level
    glog.imp('write in this node')
    glog.imp('and again')
    #close "ntr" branch
    glog.clog('ntr',['AND CLOSE'])
    #log in the first branch
    glog.inf('write in glob tree again')
    return HttpResponse('OK')


all settings (except FILE) attributes, wich used by csvlogger have prefix "CSVLOG_". And all of this variables are in the csvlog/settings.py file, with its default values, and little comments

Have fun!