Skip to main content

Posts

Showing posts with the label log

Django Log Files Viewer documents

Django Log File Viewer. This is a PYPI package django-log-file-viewer  documents. Github repo:  django-log-file-viewer@garmoncheg.github.com Usage: Useful to add log files view functionality to your Django admin web site. Instead of using database log files storage, it gives you ability to store/view log files through GUI. It requires a directory with Django log files to function. E.g. directory structure: $ project_dir / logs / : applog . log applog . log . 2012 - 09 - 22 . . . errors . log applog . log . 2012 - 09 - 22 . . . Screenshots: To parse/display these log files you need: 1. Install an app and add it to your settings.py INSTALLED_APPS section: # settings.py INSTALLED_APPS = ( # ... 'django-log-file-viewer' , # ... ) 2. Set UP 2 django variables in settings.py: # settings.py: LOG_FILES_DIR = '/path/to/your/log/directory' # Relative or static path string o...

Python: simple recipe to measure your function's execution time

We always write something unusual while doing basic things. Our own bicycles and crutches to work out some unusual situation. Here is another recipe to do a thing like so. I have tried several libraries and readymade decisions. But it assumes you have them installed. And you often try things in console, don't you? Anyway the recipe is simple and quite straightforward. import datetime # Getting first timestamp t1 = datetime . datetime . now ( ) # Your function e.g.: data = [ g . name for g in request . user . groups . all ( ) ] # Second timestamp t2 = datetime . datetime . now ( ) print "Execution time: %s" % ( t1 - t2 ) It is rude and quite simple but may often suit you well to measure execution time in a simple and straightforward manner. Also nice idea to write down this function into logs. It may be handy on refactoring of your core app for e.g.; import datetime import logging log = logging . getLogger ( 'mylogger' ) # Getting ...

Pretty git Log

SO you dislike git log output in console like me and do not use it... Because it looks like so: How about this one? It's quite easy... Just type: git log - - graph - - pretty = format : '%Cred%h%Creset -%C ( yellow ) %d%Creset %s %Cgreen ( %cr) %C ( bold blue ) <%an>%Creset' - - abbrev - commit - - It may be hard to enter such an easy command every time. Let's make an alias instead... Copypaste this to your terminal: git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --" And use simple command to see this pretty log instead: git lg Now in case you want to see lines that changed use: git lg - p In order for this command to work remove  the -- from the end of the alias. May the code be with you! NOTE: this article is a rewritten copy of  http://coderwall.com/p/euwpig?i=3&p=1&t=git   and have b...