def SaveSettings(self): fileName = self.fileNameField.GetValue() if not fileName: self.fileNameField.SetFocus() raise LoggingFileNameNotSpecified() levelName = self.levelField.GetStringSelection() level = getattr(cx_Logging, levelName) if fileName != cx_Logging.GetLoggingFileName(): cx_Logging.StartLogging(fileName, level) elif level != cx_Logging.GetLoggingLevel(): cx_Logging.SetLoggingLevel(level) self.settings.Write("LogFileName", fileName) self.settings.Write("LogLevel", levelName)
def StartLogging(self): defaultFileName = self.GetDefaultLoggingFileName() fileName = self.settings.Read("LogFileName", defaultFileName) dirName = os.path.dirname(fileName) if not os.path.isdir(dirName): os.makedirs(dirName) levelName = self.settings.Read("LogLevel", "ERROR") level = getattr(cx_Logging, levelName) maxFilesRaw = self.settings.Read("LogMaxFiles", str(self.logMaxFilesDefault)) try: maxFiles = int(maxFilesRaw) except: self.settings.DeleteEntry("LogMaxFiles") maxFiles = self.logMaxFilesDefault cx_Logging.StartLogging(fileName, level, maxFiles)
def ProcessOptions(options): """Process the options and start logging.""" logLevel = LOG_LEVEL_NAMES.get(options.logLevel.lower()) if logLevel is None: logLevel = int(options.logLevel) logPrefix = options.logPrefix if options.logFile.lower() == "stderr": cx_Logging.StartLoggingStderr(logLevel, logPrefix) elif options.logFile.lower() == "stdout": cx_Logging.StartLoggingStdout(logLevel, logPrefix) else: maxFiles = getattr(options, "maxFiles", 1) maxFileSize = getattr(options, "maxFileSize", 0) cx_Logging.StartLogging(options.logFile, logLevel, maxFiles, maxFileSize, logPrefix) f = cx_Logging.GetLoggingFile() os.dup2(f.fileno(), sys.stderr.fileno()) sys.excepthook = ExceptionHandler
) # Add the custom directory to the Python path. sys.path += [os.environ["FREPPLE_APP"]] # Initialize django import django django.setup() from django.conf import settings # Initialize logging try: cx_Logging.StartLogging( os.path.join(settings.FREPPLE_LOGDIR, "systemtray.log"), level=cx_Logging.INFO, maxFiles=1, prefix="%t", ) except: win32gui.MessageBox( None, "The folder %s doesn't exist or is not writeable for your user" % settings.FREPPLE_LOGDIR, "Error", win32con.MB_OK, ) sys.exit(1) # Redirect all output logfile = os.path.join(settings.FREPPLE_LOGDIR, "server.log") sys.stdout = sys.stderr = open(logfile, "w")
def initialize(self, configFileName): self.directory = os.path.dirname(sys.executable) cx_Logging.StartLogging(os.path.join(self.directory, "teste.log"), cx_Logging.DEBUG)
def initialize(self, config_file_name): self.directory = os.path.dirname(sys.executable) cx_Logging.StartLogging(os.path.join(self.directory, 'service.log'), cx_Logging.DEBUG) return None
from flask import Flask from app import create_app import os import sys import cx_Logging app = create_app('default') cx_Logging.Debug("stdout=%r", sys.stdout) sys.stdout = open(os.path.join("C:\\Data\\logs\\", "stdout_console.log"), "a") sys.stderr = open(os.path.join("C:\\Data\\logs\\", "stderr_console.log"), "a") cx_Logging.StartLogging(os.path.join("C:\\Data\\logs\\", "teste_console.log"), cx_Logging.DEBUG) if __name__ == "__main__": app.run(host="127.0.0.1",port=5123)
numThreads = 5 if len(sys.argv) > 2: numIterations = int(sys.argv[2]) else: numIterations = 1000 def Run(threadNum): cx_Logging.Debug("Thread-%d: starting", threadNum) iterationsLeft = numIterations while iterationsLeft > 0: numFiles = len(os.listdir(".")) cx_Logging.Debug("Thread-%d: counted %d files, %d iterations left", threadNum, numFiles, iterationsLeft) iterationsLeft -= 1 cx_Logging.StartLogging("test_threading.log", level=cx_Logging.DEBUG, maxFiles=10, maxFileSize=5 * 1024 * 1024, prefix="[%i] %t") cx_Logging.Debug("Testing logging with %s threads.", numThreads) threads = [] for i in range(numThreads): thread = threading.Thread(target=Run, args=(i + 1, )) threads.append(thread) thread.start() for thread in threads: thread.join()