예제 #1
0
class PrintLogThread(threading.Thread):
    '''
    All file printing access from one thread.

    Receives information when its placed on the passed queue.
    Called from one location: Output.handlePrint.

    Does not close the file: this happens in Output.endLogging. This
    simplifies the operation of this class, since it only has to concern
    itself with the queue.

    The path must exist before DailyLog runs for the first time.
    '''
    def __init__(self, path, queue, name):
        threading.Thread.__init__(self)
        self.queue = queue
        self.writer = DailyLogFile(name, path)

        # Don't want this to float around if the rest of the system goes down
        self.setDaemon(True)

    def run(self):
        while True:
            result = self.queue.get(block=True)

            try:
                writable = json.dumps(result)
                self.writer.write(writable + '\n')
                self.writer.flush()
            except:
                pass

            self.queue.task_done()
예제 #2
0
class PrintLogThread(threading.Thread):

    '''
    All file printing access from one thread.

    Receives information when its placed on the passed queue.
    Called from one location: Output.handlePrint.

    Does not close the file: this happens in Output.endLogging. This
    simplifies the operation of this class, since it only has to concern
    itself with the queue.

    The path must exist before DailyLog runs for the first time.
    '''

    def __init__(self, path, queue, name):
        threading.Thread.__init__(self)
        self.queue = queue
        self.writer = DailyLogFile(name, path)

        # Don't want this to float around if the rest of the system goes down
        self.setDaemon(True)

    def run(self):
        while True:
            result = self.queue.get(block=True)

            try:
                writable = json.dumps(result)
                self.writer.write(writable + '\n')
                self.writer.flush()
            except:
                pass

            self.queue.task_done()
예제 #3
0
 def write(self, data):
   if not self.enableRotation:
     if not os.path.exists(self.path):
       self.reopen()
     else:
       path_stat = os.stat(self.path)
       fd_stat = os.fstat(self._file.fileno())
       if not (path_stat.st_ino == fd_stat.st_ino and path_stat.st_dev == fd_stat.st_dev):
         self.reopen()
   DailyLogFile.write(self, data)
예제 #4
0
 def write(self, data):
   if not self.enableRotation:
     if not os.path.exists(self.path):
       self.reopen()
     else:
       path_stat = os.stat(self.path)
       fd_stat = os.fstat(self._file.fileno())
       if not (path_stat.st_ino == fd_stat.st_ino and path_stat.st_dev == fd_stat.st_dev):
         self.reopen()
   DailyLogFile.write(self, data)
예제 #5
0
파일: tylog.py 프로젝트: zhaozw/hall37
def initLog(log_file, log_path, loglevel=0):
    global log_level, _tracemsg
    log_level = loglevel
    fout = DailyLogFile(log_file, log_path)
    if _tracemsg :
        for msg in _tracemsg :
            fout.write(msg)
            fout.write('\n')
        _tracemsg = None

    class _(log.FileLogObserver):
        log.FileLogObserver.timeFormat = '%m-%d %H:%M:%S.%f'
        def emit(self, eventDict):
            taskinfo = "%r" % stackless.getcurrent() 
            eventDict['system'] = taskinfo[9:-2]   
            log.FileLogObserver.emit(self, eventDict)
    fl = _(fout)
    log.startLoggingWithObserver(fl.emit)
예제 #6
0
def initLog(log_file, log_path, loglevel=0):
    global log_level, _tracemsg
    log_level = loglevel
    fout = DailyLogFile(log_file, log_path)
    if _tracemsg:
        for msg in _tracemsg:
            fout.write(msg)
            fout.write('\n')
        _tracemsg = None

    class _(log.FileLogObserver):
        log.FileLogObserver.timeFormat = '%m-%d %H:%M:%S.%f'

        def emit(self, eventDict):
            taskinfo = "%r" % stackless.getcurrent()
            eventDict['system'] = taskinfo[9:-2]
            log.FileLogObserver.emit(self, eventDict)

    fl = _(fout)
    log.startLoggingWithObserver(fl.emit)
예제 #7
0
파일: bot.py 프로젝트: Trundle/kitbot
class ChatLogger(object):
    def __init__(self, logfile, path):
        self.log = DailyLogFile(logfile, path)
        date = datetime.now().strftime('%a %b %d %H:%M %Y')
        self.log.write('--- Log opened: %s\n' % (date, ))

    def write_line(self, line):
        self.log.write(datetime.now().strftime('%H:%M '))
        if isinstance(line, unicode):
            line = line.encode('utf-8')
        self.log.write(line)
        self.log.write('\n')
        self.log.flush()

    def action(self, nick, message):
        self.write_line(' * %s %s' % (nick, message))

    def message(self, nick, message):
        self.write_line('<%s> %s' % (nick, message))
예제 #8
0
 def write(self, data):
   if not self.enableRotation:
     if not os.path.exists(self.path):
       self.reopen()
   DailyLogFile.write(self, data)
예제 #9
0
파일: Server.py 프로젝트: verylove/YTJbc
    intervaltime=string.atof(intervaltime)
    bittime=string.atof(bittime)
    takttime=string.atof(takttime)
    if(self!=''):
        SuccessMessage(self,'01','',True)
    return 

ReadConig('')
number_of_connections = 0
echo_debug = 2 #1不显示  2基本信息  3 控制信息


application = Application("myapp")
logFile = DailyLogFile("my.log", "log")
application.setComponent(ILogObserver, FileLogObserver(logFile).emit)
logFile.write('begin...\r\n')


log.startLogging(sys.stdout)
log.msg('begin...')


############### 公共函数 ###############
def LogWrite(self,str,line='',send=''):
        ''' 记录日志  '''
        
        logstr = FormatlogMsg(self,str,line,send)
        logFile.write( logstr )
        if (DEBUGERR==True):
                if(str!=''):
                    log.msg( str )
예제 #10
0
 def write(self, data):
     if not self.enableRotation:
         if not os.path.exists(self.path):
             self.reopen()
     DailyLogFile.write(self, data)