<commit_before>#!/usr/bin/env python
#
#
import os, sys, base64, json, pprint, re, boto, syslog, pwd, logging, string, inspect, datetime


#
# Static class for logging. E.g. DXLog.warning("my warning")
# when DXLog.verbose() is called all warning messages are
# also written to stderr in additon to being captured in syslog
#
class DXLog:

    LEVELS = ('debug','info','notice','warn','error','critical','alert','emerg')
    logger = logging.getLogger(__name__)
    uname =  pwd.getpwuid(os.getuid())[0]
    program = os.path.basename(sys.argv[0])
    logger.setLevel(logging.DEBUG)
    stderr_formatter = logging.Formatter('%(program)s:%(message)s')
    dxlog_formatter = logging.Formatter('{ "login" : "%(uname)s", "source" : "%(program)s", "level" : "%(dxlevel)s", "timestamp", "%(isotime)s", "message" : "%(message)s" }')
    sh = logging.handlers.SysLogHandler("/dev/log")
    sh.setLevel(logging.DEBUG)
    sh.setFormatter(dxlog_formatter)
    logger.addHandler(sh)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)<commit_msg>use SUDO_USER to find login name for suod programs<commit_after>#!/usr/bin/env python
#
#
import os, sys, base64, json, pprint, re, boto, syslog, pwd, logging, string, inspect, datetime

def setuname():
    if os.environ['SUDO_USER']:
        return os.environ['SUDO_USER']
    else:
        return pwd.getpwuid(os.getuid())[0]

#
# Static class for logging. E.g. DXLog.warning("my warning")
# when DXLog.verbose() is called all warning messages are
# also written to stderr in additon to being captured in syslog
#
class DXLog:

    LEVELS = ('debug','info','notice','warn','error','critical','alert','emerg')
    logger = logging.getLogger(__name__)
    uname = setuname()

    program = os.path.basename(sys.argv[0])
    logger.setLevel(logging.DEBUG)
    stderr_formatter = logging.Formatter('%(program)s:%(message)s')
    dxlog_formatter = logging.Formatter('{ "login" : "%(uname)s", "source" : "%(program)s", "level" : "%(dxlevel)s", "timestamp", "%(isotime)s", "message" : "%(message)s" }')
    sh = logging.handlers.SysLogHandler("/dev/log")
    sh.setLevel(logging.DEBUG)
    sh.setFormatter(dxlog_formatter)
    logger.addHandler(sh)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
{'fraction_non_alphanumeric': 0.16903283052351376, 'fraction_numerical': 0.00354924578527063, 'mean_word_length': 4.609452736318408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3673276', 'n_tokens_mistral': 789, 'n_tokens_neox': 752, 'n_words': 166}