Exemplo n.º 1
0
def setLogLevel(level, loggerName='ROOT', temporary=True):
    """Set the log level for the given logger.
    
    Args:
        level: Logging level to set. Valid levels are 'TRACE', 'DEBUG', 'INFO',
               'WARN', 'ERROR', and 'OFF'.
                
    Optional Args:
        loggerName: Name of a specific 'logger'. Default value is 'ROOT'.
        temporary: Whether or not the logging level should be saved between
                   McIDAS-V sessions. Be aware that if set to True, loggerName
                   must be 'ROOT'. Default value is True.
                   
    Raises:
        ValueError: if temporary is True and loggerName is not 'ROOT'.
    """
    if not temporary:
        if loggerName != 'ROOT':
            raise ValueError(_BAD_LOGGERNAME % (loggerName))
        
        from edu.wisc.ssec.mcidasv.startupmanager.options import OptionMaster
        optMaster = OptionMaster.getInstance()
        optMaster.getLoggerLevelOption("LOG_LEVEL").setValue(level)
        optMaster.writeStartup()
        
    context = LoggerFactory.getILoggerFactory()
    logger = context.exists(loggerName)
    if not logger:
        logger = context.getLogger(loggerName)
    currentLevel = logger.getLevel()
    if not currentLevel:
        currentLevel = logger.getEffectiveLevel()
    convertedLevel = currentLevel.toLevel(level, currentLevel.INFO)
    logger.setLevel(convertedLevel)
Exemplo n.º 2
0
def getLogFile():
    # TODO(jon): this will likely have to change as the complexity of
    #            logback.xml increases. :(
    # should return the "default" logging context
    context = LoggerFactory.getILoggerFactory()
    assert context.getName() == 'default', _CONTEXT_ASSERT_MSG % context.getName()
    logger = context.getLogger(Logger.ROOT_LOGGER_NAME)
    # for now I'll assume that there's only ONE appender per logger
    appender = [x for x in logger.iteratorForAppenders()].pop()
    assert isinstance(appender, FileAppender), _APPENDER_ASSERT_MSG % type(appender).getCanonicalName()
    return appender.getFile()
Exemplo n.º 3
0
def getLogFile():
    # TODO(jon): this will likely have to change as the complexity of
    #            logback.xml increases. :(
    # should return the "default" logging context
    context = LoggerFactory.getILoggerFactory()
    assert context.getName() == 'default', _CONTEXT_ASSERT_MSG % context.getName()
    logger = context.getLogger(Logger.ROOT_LOGGER_NAME)
    # for now I'll assume that there's only ONE appender per logger
    appender = [x for x in logger.iteratorForAppenders()].pop()
    assert isinstance(appender, FileAppender), _APPENDER_ASSERT_MSG % type(appender).getCanonicalName()
    return appender.getFile()
Exemplo n.º 4
0
def setLogLevel(loggerName="console", logLevel="DEBUG"):
    loggerMap = {}
    logLevel = logLevel.upper()
    loggerContext = LoggerFactory.getILoggerFactory()
    loggerList = loggerContext.getLoggerList()
    for loggerItem in loggerList:
        if (loggerItem.getName() == loggerName):
            myLogger.info("Setting %s to %s" % (loggerName, logLevel))
            loggerItem.setLevel(logLevels.toLevel(logLevel))
            myLogger.info("%s = %s" % (loggerName, logLevel))
        #myLogger.error("%s != %s" % (loggerItem.getName(), loggerName))
    return
Exemplo n.º 5
0
 def __init__(self):
     func = formData.get("func")
     result = "{}"
     resultType = "text/plain"
     if func == "reindex":
         file = formData.get("file")
         portalId = formData.get("portalId")
         portalManager = Services.getPortalManager()
         if file:
             print " * Reindexing: formData=%s" % file
             portalManager.indexObject(file)
             sessionState.set("reindex/lastResult", "success")
             result = '{ status: "ok" }'
         elif portalId:
             portal = portalManager.get(portalId)
             print " * Reindexing: Portal=%s" % portal.name
             portalManager.indexPortal(portal)
             sessionState.set("reindex/lastResult", "success")
             result = '{ status: "ok" }'
         else:
             sessionState.set("reindex/lastResult", "failed")
             result = '{ status: "failed" }'
     elif func == "get-state":
         result = '{ running: "%s", lastResult: "%s" }' % \
             (sessionState.get("reindex/running"),
              sessionState.get("reindex/lastResult"))
     elif func == "get-log":
         context = LoggerFactory.getILoggerFactory()
         logger = context.getLogger("au.edu.usq.fascinator.IndexClient")
         it = logger.iteratorForAppenders()
         appender = logger.getAppender("reindex")
         layout = HTMLLayout()
         layout.setContext(context)
         layout.setPattern("%d%level%msg")
         layout.setTitle("Index log")
         layout.start()
         result = "<table>"
         count = appender.getLength()
         if count == -1:
             result += "<tr><td>Failed</td></tr>"
         elif count == 0:
             result += "<tr><td>No logging events</td></tr>"
         else:
             for i in range(0, count):
                 event = appender.get(i)
                 result += layout.doLayout(event)
         result += "</table>"
         resultType = "text/html"
     writer = response.getPrintWriter(resultType)
     writer.println(result)
     writer.close()
Exemplo n.º 6
0
 def __init__(self):
     print " * backup.py: formData=%s" % formData
     result = "{}"
     resultType = "text/plain"
     portalManager = Services.getPortalManager()
     func = formData.get("func")
     if func == "backup-view":
         print " * backup.py: backup portal %s" % portalId
         portal = portalManager.get(portalId)
         if portal:
             portalManager.backup(portal)
             sessionState.set("backup/lastResult", "success")
             result = '{ status: "ok" }'
         else:
             sessionState.set("backup/lastResult", "failed")
             result = '{ status: "failed" }'
     elif func == "get-state":
         result = '{ running: "%s", lastResult: "%s" }' % (
             sessionState.get("backup/running"),
             sessionState.get("backup/lastResult"),
         )
     elif func == "get-log":
         context = LoggerFactory.getILoggerFactory()
         logger = context.getLogger("au.edu.usq.fascinator.BackupClient")
         it = logger.iteratorForAppenders()
         appender = logger.getAppender("backup")
         layout = HTMLLayout()
         layout.setContext(context)
         layout.setPattern("%d%level%msg")
         layout.setTitle("Backup log")
         layout.start()
         result = "<table>"
         count = appender.getLength()
         if count == -1:
             result += "<tr><td>Failed</td></tr>"
         elif count == 0:
             result += "<tr><td>No logging events</td></tr>"
         else:
             for i in range(0, count):
                 event = appender.get(i)
                 result += layout.doLayout(event)
         result += "</table>"
         resultType = "text/html"
     writer = response.getPrintWriter(resultType)
     writer.println(result)
     writer.close()
Exemplo n.º 7
0
def getLogAppenders( loggerName="console" ):
    loggerMap = []
    myLogger = LoggerFactory.getLogger("logmanager")
    loggerContext = LoggerFactory.getILoggerFactory()

    myLogger.error("===================")
    appenderMap = {}
    for logger in loggerContext.getLoggerList():
        appenderList = logger.iteratorForAppenders()
        while appenderList.hasNext():
            appender = appenderList.next()
            logger.error("Logger %s" % appender.getName())
            if appender.getName() not in appenderMap.keys():
                loggerMap.append({"name": appender.getName(), "appender": "NA"})
                myLogger.error("Appender %s: %s" % (appender.getName(), "NA"))
    myLogger.error("===================")
    return loggerMap
Exemplo n.º 8
0
def createLogAppender( name, file ):
    lc = LoggerFactory.getILoggerFactory()
    ple = PatternLayoutEncoder()
    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n")
    ple.setContext(lc)
    ple.start()
    fileAppender = FileAppender()
    fileAppender.setFile(file)
    fileAppender.setEncoder(ple)
    fileAppender.setContext(lc)
    fileAppender.start()

    logger = LoggerFactory.getLogger(string)
    logger.addAppender(fileAppender)
    #logger.setLevel(logLevels.DEBUG)
    # set to true if root should log too
    logger.setAdditive(True)
    return logger
Exemplo n.º 9
0
def setLogLevel(level, loggerName='ROOT', temporary=True):
    if not temporary:
        if loggerName != 'ROOT':
            raise ValueError(_BAD_LOGGERNAME % (loggerName))
        
        from edu.wisc.ssec.mcidasv.startupmanager.options import OptionMaster
        optMaster = OptionMaster.getInstance()
        optMaster.getLoggerLevelOption("LOG_LEVEL").setValue(level)
        optMaster.writeStartup()
        
    context = LoggerFactory.getILoggerFactory()
    logger = context.exists(loggerName)
    if not logger:
        logger = context.getLogger(loggerName)
    currentLevel = logger.getLevel()
    if not currentLevel:
        currentLevel = logger.getEffectiveLevel()
    convertedLevel = currentLevel.toLevel(level, currentLevel.INFO)
    logger.setLevel(convertedLevel)
Exemplo n.º 10
0
def getLogLevel(loggerName="console"):
    loggerMap = []
    myLogger = LoggerFactory.getLogger("logmanager")
    logger = LoggerFactory.getLogger(loggerName)

    loggerContext = LoggerFactory.getILoggerFactory()
    loggerList = loggerContext.getLoggerList()
    myLogger.info("===================")
    for loggerItem in loggerList:
        if loggerItem.getLevel() is not None:
            myLogger.info("%s = %s" %
                          (loggerItem.getName(), loggerItem.getLevel()))
            loggerMap.append({
                "logger": loggerItem.getName(),
                "level": loggerItem.getLevel().toString()
            })
        else:
            myLogger.info("%s = %s" % (loggerItem.getName(), ""))
            loggerMap.append({"logger": loggerItem.getName(), "level": ""})
    myLogger.info("===================")
    return loggerMap
Exemplo n.º 11
0
import logging
from config import Config
from ch.qos.logback.classic import Level
from org.slf4j import LoggerFactory

# Configure the python logger
FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
logging.basicConfig(format=FORMAT)

# Disable the Java logger
java_logger_context = LoggerFactory.getILoggerFactory()
root_logger = java_logger_context.getLogger("ROOT")
root_logger.setLevel(Level.OFF)

# Load the singleton configuration instance to initialize
# the 'kahuna' logger
Config()
Exemplo n.º 12
0
import logging
from config import Config
from ch.qos.logback.classic import Level
from org.slf4j import LoggerFactory


# Configure the python logger
FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
logging.basicConfig(format=FORMAT)

# Disable the Java logger
java_logger_context = LoggerFactory.getILoggerFactory()
root_logger = java_logger_context.getLogger("ROOT")
root_logger.setLevel(Level.OFF)

# Load the singleton configuration instance to initialize
# the 'kahuna' logger
Config()