refs #2230: Fix logging

pull/96/head
Vadim vtroshchinskiy 2025-07-11 12:10:29 +02:00
parent c33c9ec1af
commit 7315ebe2ff
4 changed files with 79 additions and 3 deletions

View File

@ -14,6 +14,27 @@ import NetLib
from GitLib import OpengnsysGitLibrary, NTFSImplementation, OgProgressPrinterWeb
class OgLogger(logging.StreamHandler):
def emit(self, record):
log_types = ["command"]
log_level = "info"
match(record.levelno):
case logging.DEBUG:
log_level = None
case logging.WARNING:
log_level = "warning"
case logging.INFO:
log_level = "info"
case logging.ERROR:
log_level = "error"
case logging.CRITICAL:
SystemLib.ogRaiseError()
SystemLib.ogEcho(log_types, log_level, record.getMessage())
def create_image(disk_num, partition_num, repo, image_name, tagName):
ntfs_impl = NTFSImplementation.NTFS3G
@ -56,6 +77,9 @@ def main():
ip_address = NetLib.ogGetIpAddress()
logFilePath = f"{opengnsys_log_dir}/{ip_address}.log"
ogLog = OgLogger()
ogLog.setLevel(logging.DEBUG)
fileLog = logging.FileHandler(logFilePath)
fileLog.setLevel(logging.DEBUG)
@ -66,6 +90,8 @@ def main():
logger = logging.getLogger(__package__)
logger.setLevel(logging.DEBUG)
logger.addHandler(fileLog)
logger.addHandler(ogLog)
logger.info("Starting CrearImagenGit")

View File

@ -46,6 +46,28 @@ import NetLib
from GitLib import OpengnsysGitLibrary, NTFSImplementation, OgProgressPrinterWeb
class OgLogger(logging.StreamHandler):
def emit(self, record):
log_types = ["command"]
log_level = "info"
match(record.levelno):
case logging.DEBUG:
log_level = None
case logging.WARNING:
log_level = "warning"
case logging.INFO:
log_level = "info"
case logging.ERROR:
log_level = "error"
case logging.CRITICAL:
SystemLib.ogRaiseError()
print("HERE!")
SystemLib.ogEcho(log_types, log_level, record.getMessage())
def commit_image(disk_num, partition_num, repo, image_name, msg):
ntfs_impl = NTFSImplementation.NTFS3G
@ -53,8 +75,7 @@ def commit_image(disk_num, partition_num, repo, image_name, msg):
og_git.progress_callback = OgProgressPrinterWeb()
device = DiskLib.ogDiskToDev(disk_num, partition_num)
og_git.initRepo(device, image_name)
og_git.commit(device, msg)
og_git.commit(device = device, message = msg)
og_git.push()
def main():
@ -72,6 +93,9 @@ def main():
ip_address = NetLib.ogGetIpAddress()
logFilePath = f"{opengnsys_log_dir}/{ip_address}.log"
ogLog = OgLogger()
ogLog.setLevel(logging.DEBUG)
fileLog = logging.FileHandler(logFilePath)
fileLog.setLevel(logging.DEBUG)
@ -82,6 +106,7 @@ def main():
logger = logging.getLogger(__package__)
logger.setLevel(logging.DEBUG)
logger.addHandler(fileLog)
logger.addHandler(ogLog)
logger.info("Starting ModificarImagenGit")

View File

@ -10,6 +10,27 @@ import DiskLib
from GitLib import OpengnsysGitLibrary, NTFSImplementation, OgProgressPrinterWeb
class OgLogger(logging.StreamHandler):
def emit(self, record):
log_types = ["command"]
log_level = "info"
match(record.levelno):
case logging.DEBUG:
log_level = None
case logging.WARNING:
log_level = "warning"
case logging.INFO:
log_level = "info"
case logging.ERROR:
log_level = "error"
case logging.CRITICAL:
SystemLib.ogRaiseError()
SystemLib.ogEcho(log_types, log_level, record.getMessage())
if __name__ == "__main__":
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
try:
@ -35,6 +56,9 @@ if __name__ == "__main__":
opengnsys_log_dir = "/opt/opengnsys/log"
ip_address = NetLib.ogGetIpAddress()
logFilePath = f"{opengnsys_log_dir}/{ip_address}.log"
ogLog = OgLogger()
ogLog.setLevel(logging.DEBUG)
fileLog = logging.FileHandler(logFilePath)
fileLog.setLevel(logging.DEBUG)
@ -46,6 +70,7 @@ if __name__ == "__main__":
logger = logging.getLogger(__package__)
logger.setLevel(logging.DEBUG)
logger.addHandler(fileLog)
logger.addHandler(ogLog)
logger.info("Starting RestaurarImagenGit")

View File

@ -1567,7 +1567,7 @@ class OpengnsysGitLibrary:
if path is None:
path = self.fs.ensure_mounted(device)
self.logger.info("Committing changes to repository")
self.logger.info("Committing changes from %s to repository", path)
repo = git.Repo(path)
self._create_metadata(path, initial_creation=False)