Merge pull request 'oglog' (#27) from oglog into main
Reviewed-on: opengnsys/ogclone-engine#27move-ogGetIpAddress 0.5.0
commit
e885302256
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.5.0] - 2025-04-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Log to /var/log/clone-engine.log and clone-engine.json.log
|
||||||
|
|
||||||
## [0.4.1] - 2025-04-10
|
## [0.4.1] - 2025-04-10
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -3,6 +3,7 @@ import datetime
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import inspect
|
import inspect
|
||||||
import glob
|
import glob
|
||||||
|
@ -20,6 +21,7 @@ import StringLib
|
||||||
|
|
||||||
def _logtype2logfile (t):
|
def _logtype2logfile (t):
|
||||||
if 'log' == t.lower(): return ogGlobals.OGLOGFILE
|
if 'log' == t.lower(): return ogGlobals.OGLOGFILE
|
||||||
|
if 'jsonlog' == t.lower(): return ogGlobals.OGJSONLOGFILE
|
||||||
elif 'command' == t.lower(): return ogGlobals.OGLOGCOMMAND
|
elif 'command' == t.lower(): return ogGlobals.OGLOGCOMMAND
|
||||||
elif 'session' == t.lower(): return ogGlobals.OGLOGSESSION
|
elif 'session' == t.lower(): return ogGlobals.OGLOGSESSION
|
||||||
else: raise Exception (f'unknown log type ({t})')
|
else: raise Exception (f'unknown log type ({t})')
|
||||||
|
@ -35,24 +37,40 @@ def ogEcho (logtypes, loglevel, msg):
|
||||||
logfiles = ['/dev/stdout']
|
logfiles = ['/dev/stdout']
|
||||||
if type (logtypes) is list:
|
if type (logtypes) is list:
|
||||||
for l in logtypes:
|
for l in logtypes:
|
||||||
logfiles.append (_logtype2logfile (l))
|
if 'log' == l:
|
||||||
|
logfiles.append (_logtype2logfile ('log'))
|
||||||
|
logfiles.append (_logtype2logfile ('jsonlog'))
|
||||||
|
else:
|
||||||
|
logfiles.append (_logtype2logfile (l))
|
||||||
else: ## string
|
else: ## string
|
||||||
logfiles.append (_logtype2logfile (logtypes))
|
if 'log' == logtypes:
|
||||||
|
logfiles.append (_logtype2logfile ('log'))
|
||||||
|
logfiles.append (_logtype2logfile ('jsonlog'))
|
||||||
|
else:
|
||||||
|
logfiles.append (_logtype2logfile (logtypes))
|
||||||
|
|
||||||
if loglevel is None or 'help' == loglevel:
|
if loglevel is None or 'help' == loglevel:
|
||||||
if ogGlobals.DEBUG.lower() != "no":
|
if ogGlobals.DEBUG.lower() != "no":
|
||||||
logfiles.append (ogGlobals.OGLOGFILE)
|
logfiles.append (ogGlobals.OGLOGFILE)
|
||||||
|
logfiles.append (ogGlobals.OGJSONLOGFILE)
|
||||||
for f in logfiles:
|
for f in logfiles:
|
||||||
with open (f, 'a') as fd:
|
with open (f, 'a') as fd:
|
||||||
fd.write (msg + '\n')
|
if ogGlobals.OGJSONLOGFILE == f:
|
||||||
|
fd.write (json.dumps ({'message':msg}) + '\n')
|
||||||
|
else:
|
||||||
|
fd.write (msg + '\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'info' == loglevel or 'warning' == loglevel or 'error' == loglevel:
|
if 'info' == loglevel or 'warning' == loglevel or 'error' == loglevel:
|
||||||
DATETIME = datetime.datetime.now(ZoneInfo(ogGlobals.TZ)).strftime("%F %T %Z")
|
DATETIME = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%F %T %Z')
|
||||||
|
DATETIME_json = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
for f in logfiles:
|
for f in logfiles:
|
||||||
with open (f, 'a') as fd:
|
with open (f, 'a') as fd:
|
||||||
fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n")
|
if ogGlobals.OGJSONLOGFILE == f:
|
||||||
|
fd.write (json.dumps ({'timestamp':DATETIME_json, 'severity':loglevel, 'message':msg}) + '\n')
|
||||||
|
else:
|
||||||
|
fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n")
|
||||||
else:
|
else:
|
||||||
raise Exception (f'unknown loglevel ({loglevel})')
|
raise Exception (f'unknown loglevel ({loglevel})')
|
||||||
|
|
||||||
|
@ -75,10 +93,18 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
|
||||||
if type (logtypes) is list:
|
if type (logtypes) is list:
|
||||||
for l in logtypes:
|
for l in logtypes:
|
||||||
logtypes = list (map (lambda x: x.lower(), logtypes))
|
logtypes = list (map (lambda x: x.lower(), logtypes))
|
||||||
logfiles.append (_logtype2logfile (l))
|
if 'log' == l:
|
||||||
|
logfiles.append (_logtype2logfile ('log'))
|
||||||
|
logfiles.append (_logtype2logfile ('jsonlog'))
|
||||||
|
else:
|
||||||
|
logfiles.append (_logtype2logfile (l))
|
||||||
else: ## string
|
else: ## string
|
||||||
logtypes = logtypes.lower()
|
logtypes = logtypes.lower()
|
||||||
logfiles.append (_logtype2logfile (logtypes))
|
if 'log' == logtypes:
|
||||||
|
logfiles.append (_logtype2logfile ('log'))
|
||||||
|
logfiles.append (_logtype2logfile ('jsonlog'))
|
||||||
|
else:
|
||||||
|
logfiles.append (_logtype2logfile (logtypes))
|
||||||
|
|
||||||
if not fun:
|
if not fun:
|
||||||
ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'no function provided')
|
ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'no function provided')
|
||||||
|
@ -103,7 +129,6 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
|
||||||
# ## redirect stdout only
|
# ## redirect stdout only
|
||||||
# eval $COMMAND | tee -a $FILES
|
# eval $COMMAND | tee -a $FILES
|
||||||
|
|
||||||
import time
|
|
||||||
sout = serr = ''
|
sout = serr = ''
|
||||||
if 'command' in logtypes:
|
if 'command' in logtypes:
|
||||||
os.unlink (ogGlobals.OGLOGCOMMAND)
|
os.unlink (ogGlobals.OGLOGCOMMAND)
|
||||||
|
@ -121,14 +146,19 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
|
||||||
if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str):
|
if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str):
|
||||||
for f in logfiles:
|
for f in logfiles:
|
||||||
with open (f, 'a') as fd:
|
with open (f, 'a') as fd:
|
||||||
if sout: fd.write (f'{sout}\n')
|
if ogGlobals.OGJSONLOGFILE == f:
|
||||||
if serr: fd.write (f'{serr}\n')
|
if sout: fd.write (json.dumps ({'message':sout}) + '\n')
|
||||||
if rc_str: fd.write (f'{rc_str}\n')
|
if serr: fd.write (json.dumps ({'message':serr}) + '\n')
|
||||||
#fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n")
|
if rc_str: fd.write (json.dumps ({'message':rc_str}) + '\n')
|
||||||
#if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n")
|
else:
|
||||||
#else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n")
|
if sout: fd.write (f'{sout}\n')
|
||||||
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
|
if serr: fd.write (f'{serr}\n')
|
||||||
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
|
if rc_str: fd.write (f'{rc_str}\n')
|
||||||
|
#fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n")
|
||||||
|
#if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n")
|
||||||
|
#else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n")
|
||||||
|
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
|
||||||
|
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,9 @@ OGPYFUNCS = os.path.join (OPENGNSYS, 'functions')
|
||||||
OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts')
|
OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts')
|
||||||
OGIMG = os.path.join (OPENGNSYS, 'images')
|
OGIMG = os.path.join (OPENGNSYS, 'images')
|
||||||
OGCAC = os.path.join (OPENGNSYS, 'cache')
|
OGCAC = os.path.join (OPENGNSYS, 'cache')
|
||||||
OGLOG = os.path.join (OPENGNSYS, 'log')
|
OGLOG = '/var/log'
|
||||||
OGLOGFILE = f'{OGLOG}/{ip}.log'
|
OGLOGFILE = f'{OGLOG}/clone-engine.log'
|
||||||
|
OGJSONLOGFILE = f'{OGLOG}/clone-engine.json.log'
|
||||||
DEBUG = 'yes'
|
DEBUG = 'yes'
|
||||||
_path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin'
|
_path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin'
|
||||||
os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN])
|
os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN])
|
||||||
|
|
Loading…
Reference in New Issue