<commit_before>#
# Description: log support module
#
# Author:
#  <NAME> (Oct 25th 2006)
#
import time

# this class can be used instead of a file for writing
class DayLogFile:
    def __init__(self,base_fname):
        self.base_fname=base_fname
        return

    def close(self):
        return # nothing to do, just a placeholder

    def write(self,msg):
        now=time.time()
        fname=self.__get_fname()
        try:
            fd=open(fname,"a")
        except:
            self.write_on_exception("Cannot open %s"%fname,msg)
        try:
            try:
                fd.write(self.format_msg(now,msg))
            except:
                self.write_on_exception("Cannot open %s"%fname,msg)
        finally:
            fd.close()
        
        return

    ##########################
    # these can be customized
    ##########################

    def write_on_exception(self,exception_msg,msg):
        return # do nothing

    def get_fname(self,timestamp):
        return "%s.%s.log"%(self.base_fname,time.strftime("%Y%m%d",time.localtime(timestamp)))

    def format_msg(self,timestamp,msg):
        return "[%s %s] %s"%(self.format_time(timestamp),os.getpid(),msg)

    def format_time(self,timestamp):
        return "%li"%timestamp

<commit_msg>Printout on error<commit_after>#
# Description: log support module
#
# Author:
#  <NAME> (Oct 25th 2006)
#
import time

# this class can be used instead of a file for writing
class DayLogFile:
    def __init__(self,base_fname):
        self.base_fname=base_fname
        return

    def close(self):
        return # nothing to do, just a placeholder

    def write(self,msg):
        now=time.time()
        fname=self.__get_fname()
        try:
            fd=open(fname,"a")
        except:
            self.write_on_exception("Cannot open %s"%fname,msg)
        try:
            try:
                fd.write(self.format_msg(now,msg))
            except:
                self.write_on_exception("Cannot open %s"%fname,msg)
        finally:
            fd.close()
        
        return

    ##########################
    # these can be customized
    ##########################

    def write_on_exception(self,exception_msg,msg):
        print "%s: %s" % (exception_msg,msg)
        return 

    def get_fname(self,timestamp):
        return "%s.%s.log"%(self.base_fname,time.strftime("%Y%m%d",time.localtime(timestamp)))

    def format_msg(self,timestamp,msg):
        return "[%s %s] %s"%(self.format_time(timestamp),os.getpid(),msg)

    def format_time(self,timestamp):
        return "%li"%timestamp


{'fraction_non_alphanumeric': 0.15360864531069085, 'fraction_numerical': 0.004631416441528367, 'mean_word_length': 2.4376657824933687, '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': '4180341', 'n_tokens_mistral': 831, 'n_tokens_neox': 796, 'n_words': 166}