1
This commit is contained in:
parent
30c25277eb
commit
d4586eabaa
13
f7/udplog.py
13
f7/udplog.py
@ -1,11 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import traceback
|
import traceback
|
||||||
import _thread
|
import _thread
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
import q7
|
||||||
|
|
||||||
class _LocalLogNode:
|
class _LocalLogNode:
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
@ -21,6 +24,7 @@ class _UdpLog:
|
|||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self._logDir = ''
|
||||||
self._topNode = None
|
self._topNode = None
|
||||||
self._botNode = None
|
self._botNode = None
|
||||||
self._workNode = None
|
self._workNode = None
|
||||||
@ -29,6 +33,11 @@ class _UdpLog:
|
|||||||
def init(self):
|
def init(self):
|
||||||
_thread.start_new_thread(self._saveToFile, ())
|
_thread.start_new_thread(self._saveToFile, ())
|
||||||
|
|
||||||
|
def setLogDirAndCreate(self, logdir):
|
||||||
|
if not os.path.exists(logdir):
|
||||||
|
os.makedirs(logdir)
|
||||||
|
self._logDir = logdir
|
||||||
|
|
||||||
def unInit(self):
|
def unInit(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -72,9 +81,9 @@ class _UdpLog:
|
|||||||
finally:
|
finally:
|
||||||
self._msgLock.release()
|
self._msgLock.release()
|
||||||
if self._workNode:
|
if self._workNode:
|
||||||
filename = datetime.datetime.now().strftime('log%Y-%m-%d.log')
|
filename = datetime.datetime.now().strftime('log_' + str(os.getpid()) + '_%Y%m%d.log')
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(LOG_DIR, filename), 'a') as f:
|
with open(os.path.join(self._logDir, filename), 'a') as f:
|
||||||
while self._workNode:
|
while self._workNode:
|
||||||
nextNode = self._workNode.nextNode
|
nextNode = self._workNode.nextNode
|
||||||
f.write(self._workNode.msg + '\r\n')
|
f.write(self._workNode.msg + '\r\n')
|
||||||
|
@ -8,4 +8,6 @@ sys.path.append('..')
|
|||||||
import f7.udplog
|
import f7.udplog
|
||||||
|
|
||||||
f7.udplog.instance().init()
|
f7.udplog.instance().init()
|
||||||
time.sleep(5)
|
f7.udplog.instance().setLogDirAndCreate('/data/logs/f7test/logs')
|
||||||
|
f7.udplog.instance().info('start')
|
||||||
|
time.sleep(15)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user