Skip to content

Instantly share code, notes, and snippets.

View ipmb's full-sized avatar

Peter Baumgartner ipmb

View GitHub Profile
from __future__ import unicode_literals
import logging
# built-in attributes on LogRecord. Used to determine what is passed in `extras`
RESERVED_ATTRS = (
'args', 'asctime', 'created', 'exc_info', 'exc_text', 'filename',
'funcName', 'levelname', 'levelno', 'lineno', 'module',
'msecs', 'message', 'msg', 'name', 'pathname', 'process',
'processName', 'relativeCreated', 'stack_info', 'thread', 'threadName')
@ipmb
ipmb / settings.py
Last active November 24, 2023 20:25
Django logging example
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
@ipmb
ipmb / 0_default_tree.md
Last active May 17, 2022 00:37
Django Logging Variations

Default Django Logging Tree

app.py

#!/usr/bin/env python
import os

import django
import logging_tree
@ipmb
ipmb / create_test_instance.sls
Last active June 13, 2017 23:12
Salt orchestration
{% set branch = pillar.name.split('.', 1)[0] %}
{{ branch }} db:
salt.function:
- name: state.apply
- tgt: salt.example.local
- arg:
- projects.test.dbs.generate_from_template
- kwarg:
pillar:
@ipmb
ipmb / cloudwatch_sysstats.py
Created March 3, 2017 03:59
Send system stats to AWS Cloudwatch with Python
# -*- coding: utf-8 -*-
import os
# pip install boto3 psutil requests
import boto3
import psutil
import requests
NAMESPACE = 'Sys'
os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1')
@ipmb
ipmb / Procfile
Created January 10, 2017 16:39
broken buildpack
web: server.py
# er/sites/site1.sls
SITE_ID: 14
EMAIL: support@site1.com
LOG_FILE_DIR: /var/log/er_site1
@ipmb
ipmb / gist:75be883defe09fc3dc32
Created January 7, 2016 20:21
Django 1.9.1 makemigrations
$ python -m cProfile -s time ./manage.py makemigrations --empty pages
Migrations for 'pages':
0014_auto_20160107_1519.py:
66325365 function calls (65778093 primitive calls) in 157.981 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
306135 10.721 0.000 16.741 0.000 __init__.py:139(__init__)
203638 8.801 0.000 14.381 0.000 __init__.py:370(deconstruct)
@ipmb
ipmb / gist:e65159f7315b9645841b
Last active January 7, 2016 19:09
Django migrations cprofile
$ manage.py showmigrations | grep "\[" | wc -l
85
$ echo "\d" | psql mydb | grep -v sequence | wc -l
299
$ time python -m cProfile -s time ./manage.py makemigrations --empty pages
Migrations for 'pages':
0014_auto_20160107_1356.py:
108764127 function calls (108404501 primitive calls) in 264.744 seconds
Ordered by: internal time
#!/bin/bash
PYPYVENV="~/db-pypy"
CPYVENV="~/db-cpy"
virtualenv --python=`which pypy` $PYPYVENV
virtualenv $CPYVENV
$PYPYVENV/bin/pip install -e git://github.com/django/djangobench.git#egg=djangobench
$CPYVENV/bin/pip install -e git://github.com/django/djangobench.git#egg=djangobench