<commit_before>from django.contrib.auth.models import User
from django.core.validators import ip_address_validators
from apps.core.models import UserLog
from logging.handlers import RotatingFileHandler


class FileHandler(RotatingFileHandler, object):
    def emit(self, record):
        record.ip = '0.0.0.0'
        record.username = 'undefined'

        request = record.args.get('r', None)
        if request:
            ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
            try:
                ip_address_validators('both', ip)
            except:
                ip = '0.0.0.0'
            record.ip = ip

            if request.user.is_authenticated():
                record.username = request.user.username

        if record.args.has_key('uid'):
            record.username = record.args['uid']

        hide = record.args.has_key('hide')
        user = User.objects.filter(username=record.username).first()
        if user and not hide:
            manager = user.user_logs
            if manager.count() >= 30:
                manager.order_by('time')[0].delete()
            UserLog(user=user, level=record.levelno, ip=record.ip,
                    text='%s.%s' % (record.name, record.getMessage())).save()
<commit_msg>fix RemovedInDjango19Warning on logger<commit_after>from django.core.validators import ip_address_validators
from django.apps import apps
from logging.handlers import RotatingFileHandler


class FileHandler(RotatingFileHandler, object):
    def emit(self, record):
        record.ip = '0.0.0.0'
        record.username = 'undefined'

        request = record.args.get('r', None)
        if request:
            ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
            try:
                ip_address_validators('both', ip)
            except:
                ip = '0.0.0.0'
            record.ip = ip

            if request.user.is_authenticated():
                record.username = request.user.username

        if record.args.has_key('uid'):
            record.username = record.args['uid']

        hide = record.args.has_key('hide')

        UserProfile = apps.get_model('core', 'UserProfile')
        profile = UserProfile.objects.filter(user__username=record.username).first()
        if profile and not hide:
            manager = profile.user.user_logs
            if manager.count() >= 30:
                manager.order_by('time')[0].delete()
            UserLog = apps.get_model('core', 'UserLog')
            UserLog(user=profile.user, level=record.levelno, ip=record.ip,
                    text='%s.%s' % (record.name, record.getMessage())).save()

{'fraction_non_alphanumeric': 0.12351361718450327, 'fraction_numerical': 0.01227464518603759, 'mean_word_length': 2.153567110036276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3252495', 'n_tokens_mistral': 775, 'n_tokens_neox': 742, 'n_words': 147}