Пример #1
0
def log( log_msg, error_code = 0, display = True ):
    
    conf_obj = conf_handler.conf_handler(conf_name = "logger.conf")

    debug_mode = conf_obj.read_conf( "debug" )
    if(debug_mode == "false"): return

    file_path = conf_obj.read_conf( "file_path" )
    if( file_path == None ):
        if (os.path.exists('../log/') ): file_path = "../log/log_file.log"
        else: file_path = "/tmp/log_file.log"

    try:
        log_file = open(file_path, 'a')

    except IOError:
        file_handler.create_folder("./log") # creates folder (if it don't exist yet)
        log_file = open(file_path, 'a')

    date = str(datetime.datetime.now())

    # retreive the outer frame that calls the actual function
    info = inspect.currentframe().f_back

    line = info.f_lineno
    filename = info.f_code.co_filename
    
    del info

    log_line = time.strftime("%d %b %Y %H:%M:%S") + ":" + filename + "," + str(line) + ":" + str(error_code) + ": " + log_msg+"\n"
    
    try:
        log_file.write(log_line);
    except IOError:
        return "IOError"

    if(display):
        print log_line

    log_file.close();

    file_size = file_handler.get_file_size(file_path)
    max_size = conf_obj.read_conf( "max_log_file_size" )

    if( max_size == None ): 
        max_size = 10000000

    if( int(file_size) > int(max_size) ):
        file_handler.copy_file( file_path, file_path + ".old" )
        os.remove( file_path )

    del conf_obj
Пример #2
0
    def __init__( self ):
        conf = conf_handler.conf_handler(conf_name = __m_module_name + ".conf")
        if (conf == None):
            logger.log("Unable to load config file "+ __m_module_name + ".conf" )
            return
        
        notifications_path = conf.read_conf("notifications_path")
        if (notifications_path == None):
            logger.log("Unable to find notifications path in config." )
            return

        __m_notification_json = json_handler.json_handler(notifications_path)
        if ( __m_notification_json == None):
            logger.log("Unable to load json file " + __m_notification_json )
            return