<commit_before># -*- coding: utf-8 -*-
"""
    wakatime.log
    ~~~~~~~~~~~~

    Provides the configured logger for writing JSON to the log file.

    :copyright: (c) 2013 <NAME>.
    :license: BSD, see LICENSE for more details.
"""

import json
import logging
import os

try:
    from collections import OrderedDict
except ImportError:
    from .packages.ordereddict import OrderedDict


class CustomEncoder(json.JSONEncoder):

    def default(self, obj):
        return super(CustomEncoder, self).default(obj)


class JsonFormatter(logging.Formatter):

    def __init__(self, timestamp, endtime, isWrite, targetFile, version,
            plugin, datefmt=None):
        self.timestamp = timestamp
        self.endtime = endtime
        self.isWrite = isWrite
        self.targetFile = targetFile
        self.version = version
        self.plugin = plugin
        super(JsonFormatter, self).__init__(datefmt=datefmt)

    def format(self, record):
        data = OrderedDict([
            ('now', self.formatTime(record, self.datefmt)),
            ('version', self.version),
            ('plugin', self.plugin),
            ('time', self.timestamp),
            ('endtime', self.endtime),
            ('isWrite', self.isWrite),
            ('file', self.targetFile),
            ('level', record.levelname),
            ('message', record.msg),
        ])
        if not self.endtime:
            del data['endtime']
        if not self.plugin:
            del data['plugin']
        if not self.isWrite:
            del data['isWrite']
        return CustomEncoder().encode(data)

    def formatException(self, exc_info):
        return exec_info[2].format_exc()


def setup_logging(args, version):
    logfile = args.logfile
    if not logfile:
        logfile = '~/.wakatime.log'
    handler = logging.FileHandler(os.path.expanduser(logfile))
    formatter = JsonFormatter(
        timestamp=args.timestamp,
        endtime=args.endtime,
        isWrite=args.isWrite,
        targetFile=args.targetFile,
        version=version,
        plugin=args.plugin,
        datefmt='%Y-%m-%dT%H:%M:%SZ',<commit_msg>fixed bug in custom logger where calling super() on old-style class throws exception.<commit_after># -*- coding: utf-8 -*-
"""
    wakatime.log
    ~~~~~~~~~~~~

    Provides the configured logger for writing JSON to the log file.

    :copyright: (c) 2013 <NAME>.
    :license: BSD, see LICENSE for more details.
"""

import json
import logging
import os

try:
    from collections import OrderedDict
except ImportError:
    from .packages.ordereddict import OrderedDict


class CustomEncoder(json.JSONEncoder):

    def default(self, obj):
        return super(CustomEncoder, self).default(obj)


class JsonFormatter(logging.Formatter):

    def setup(self, timestamp, endtime, isWrite, targetFile, version, plugin):
        self.timestamp = timestamp
        self.endtime = endtime
        self.isWrite = isWrite
        self.targetFile = targetFile
        self.version = version
        self.plugin = plugin

    def format(self, record):
        data = OrderedDict([
            ('now', self.formatTime(record, self.datefmt)),
            ('version', self.version),
            ('plugin', self.plugin),
            ('time', self.timestamp),
            ('endtime', self.endtime),
            ('isWrite', self.isWrite),
            ('file', self.targetFile),
            ('level', record.levelname),
            ('message', record.msg),
        ])
        if not self.endtime:
            del data['endtime']
        if not self.plugin:
            del data['plugin']
        if not self.isWrite:
            del data['isWrite']
        return CustomEncoder().encode(data)

    def formatException(self, exc_info):
        return exec_info[2].format_exc()


def setup_logging(args, version):
    logfile = args.logfile
    if not logfile:
        logfile = '~/.wakatime.log'
    handler = logging.FileHandler(os.path.expanduser(logfile))
    formatter = JsonFormatter(datefmt='%Y-%m-%dT%H:%M:%SZ')
    formatter.setup(
        timestamp=args.timestamp,
        endtime=args.endtime,
        isWrite=args.isWrite,
        targetFile=args.targetFile,
        version=version,
        plugin=args.plugin,
{'fraction_non_alphanumeric': 0.12162162162162163, 'fraction_numerical': 0.002844950213371266, 'mean_word_length': 2.418962722852512, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2797810', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1171, 'n_words': 294}