Update log in programma test e ufficiale x seriale

This commit is contained in:
Samuele Locatelli
2024-06-12 10:00:44 +02:00
parent c185910064
commit a40c45aba9
5 changed files with 24 additions and 120 deletions
+4 -5
View File
@@ -10,21 +10,20 @@ BASE_PATH = os.path.dirname(__file__) + '\\'
LOGFILE='my_logger.log'
logPath = os.path.join(BASE_PATH, LOGFILE)
# Define a custom formatter
formatter = logging.Formatter('%(asctime)s %(name)-8s %(levelname)-8s %(message)s')
logFormat = '%(asctime)s | %(name)-8s | %(levelname)-8s | %(message)s'
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('MainLog')
logCheck = logging.getLogger('CheckLog')
logTask = logging.getLogger('taskLog')
#handler = RotatingFileHandler(logPath, maxBytes=2000, backupCount=10)
# gestore handler x logrotate
handler = RotatingFileHandler(logPath,
maxBytes=1024*16,
backupCount=10
)
# Define a custom formatter
formatter = logging.Formatter('%(asctime)s %(name)-8s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
+15 -34
View File
@@ -49,12 +49,12 @@ class IobWinStatus:
#--------------------------------------------------------------
MAY_LOG_FILE = 30
SAMPLETIME = 0.1
LOGFILE = 'logfile.txt'
LOGFILE = 'logfile.log'
LOGLEVEL = 1
PROGRAM_NAME= 'TEST LOG'
IOB_NAME='IOB'
IOB_CONF='IOB.cfg'
MAX_LOG_SIZE = 1024
MAX_LOG_SIZE = 1024 * 16
NUM_LOG_RETAIN = 5
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
@@ -84,8 +84,6 @@ def checkLog():
try:
# verifico logfile...
logPro.info("verifica log")
# logPath = os.path.join(BASE_LOG_PATH, LOGFILE)
# fileSize = os.path.getsize(logPath)
except Exception as exc :
sys.stdout.write ( '\n errore in checkLog \n\n' )
@@ -95,8 +93,6 @@ def checkLog():
# funzione WatchDog verso REDIS
#---------------------------------------------------------------
def sendWatchDog():
# creo un NUOVO logger..
logTask = logging.getLogger('taskLog')
# invio su redis stato
adesso = datetime.now()
redIobMan.lastUpdate=adesso.strftime("%Y-%m-%d %H:%M:%S")
@@ -107,7 +103,7 @@ def sendWatchDog():
rawVal = redIobMan.toJSON()
redSrv0.set(f'IOB-WIN-PSER-TEST:IOB:{IOB_NAME}', rawVal)
# redSrv0.set(f'Python:IobWinStatus:{IOB_CONF}', adesso.strftime("%H:%M:%S"))
logTask.debug('Invio a REDIS segnale watchdog')
logSnd.debug('Invio a REDIS segnale watchdog')
#----------------------------------------------------------------------
# Setup
@@ -138,8 +134,8 @@ try:
confFilePath = os.path.join(BASE_PATH, 'CONF', IOB_CONF)
config.read(confFilePath)
# lettura parametri
LOGFILE = config.get('log','LOGFILE')
LOGLEVEL = config.getint('log','LOGLEVEL')
#LOGFILE = config.get('log','LOGFILE')
#LOGLEVEL = config.getint('log','LOGLEVEL')
SAMPLETIME = config.getfloat('time','SAMPLETIME')
#MAX_LOG_SIZE = config.getint('log','MAX_LOG_SIZE')
NUM_LOG_RETAIN = config.getint('log','NUM_LOG_RETAIN')
@@ -191,27 +187,23 @@ try:
elif LOGLEVEL > 5:
cLogLevel = logging.INFO
logging.basicConfig(level=logging.DEBUG,
filename=logPath,
format='%(asctime)s %(name)-8s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
logging.basicConfig(level=logging.DEBUG)
# add a rotating handler
#logPath = os.path.join(BASE_LOG_PATH, LOGFILE)
handler = RotatingFileHandler(logPath,
maxBytes=MAX_LOG_SIZE,
backupCount=NUM_LOG_RETAIN
)
# Define a custom formatter
formatter = logging.Formatter('%(asctime)s %(name)-8s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
# aggiungo logger specifici (program,queue,send...)
logQue = logging.getLogger('queue')
logQue2 = logging.getLogger('queue2')
logSnd = logging.getLogger('sendUrl')
logPro = logging.getLogger('program')
logQue.addHandler(handler)
logQue2.addHandler(handler)
logQue.addHandler(handler)
logSnd.addHandler(handler)
logPro.addHandler(handler)
@@ -225,27 +217,16 @@ except Exception as exc:
#--------------------------------------------
do_every ( 3 , checkLog )
do_every ( 1 , sendWatchDog )
do_every ( 0.3 , checkLog )
do_every ( 0.1 , sendWatchDog )
logPro.info( "Start " + PROGRAM_NAME )
cLog=0
def is_even(num):
return num % 2 == 0
while True :
try:
time.sleep (SAMPLETIME * 5)
time.sleep (SAMPLETIME)
except:
logPro.error("Errore attesa SAMPLETIME")
cLog +=1
# salto tra 2 log ogni scrittura x evitare si pestino i piedi...
if is_even(cLog) :
logQue.info( "Test Scrittura | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
else :
logQue2.info( "Test Scrittura | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
logQue.info( "Test Scrittura | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ | 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
-38
View File
@@ -1,38 +0,0 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['IOB-WIN-PSER-TEST.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='IOB-WIN-PSER-TEST',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['SteamWare.ico'],
)
+5 -5
View File
@@ -545,11 +545,7 @@ try:
elif LOGLEVEL > 5:
cLogLevel = logging.INFO
logging.basicConfig(level=cLogLevel,
filename=logPath,
format='%(asctime)s %(name)-8s %(levelname)-8s %(message)s',
datefmt='%Y.%m.%d %H:%M:%S'
)
logging.basicConfig(level=cLogLevel)
# add a rotating handler
handler = RotatingFileHandler(logPath,
@@ -557,6 +553,10 @@ try:
backupCount=NUM_LOG_RETAIN
)
# Define a custom formatter
formatter = logging.Formatter('%(asctime)s %(name)-8s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
# aggiungo logger specifici (program,queue,send...)
logQue = logging.getLogger('queue')
logSnd = logging.getLogger('sendUrl')
-38
View File
@@ -1,38 +0,0 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['IOB-WIN-PSER.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='IOB-WIN-PSER',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['SteamWare.ico'],
)