Changeset: 4c7a0b8cef8e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4c7a0b8cef8e
Added Files:
        gdk/gdk_stalker.c
        gdk/gdk_stalker.h
Removed Files:
        common/mlogger/Makefile.ag
        common/mlogger/mlogger.c
        common/mlogger/mlogger.h
Modified Files:
        common/Makefile.ag
        gdk/Makefile.ag
        gdk/gdk_utils.c
        monetdb5/mal/Makefile.ag
        monetdb5/mal/mal.c
        tools/mserver/Makefile.ag
        tools/mserver/mserver5.c
Branch: mlogger
Log Message:

Various changes (mlogger -> GDKstalker)
- Renamed mlogger to GDKstalker and moved to the context of GDK
- Replaced exit calls with asserts
- API calls return gdk_return
- Replaced some variables with ATOMIC_TYPE
- Do not overwrite values of log/flush level when not necessary
- If message does not fit an empty buffer -> cut it off


diffs (truncated from 946 to 300 lines):

diff --git a/common/Makefile.ag b/common/Makefile.ag
--- a/common/Makefile.ag
+++ b/common/Makefile.ag
@@ -4,4 +4,4 @@
 #
 # Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
 
-SUBDIRS = stream options utils mlogger
+SUBDIRS = stream options utils
diff --git a/common/mlogger/Makefile.ag b/common/mlogger/Makefile.ag
deleted file mode 100644
--- a/common/mlogger/Makefile.ag
+++ /dev/null
@@ -1,13 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0.  If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-# Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
-
-## Process this file with automake to produce Makefile.in
-
-MTSAFE
-
-lib_mlogger  =  {
-    SOURCES = mlogger.c mlogger.h
-}
diff --git a/common/mlogger/mlogger.c b/common/mlogger/mlogger.c
deleted file mode 100644
--- a/common/mlogger/mlogger.c
+++ /dev/null
@@ -1,296 +0,0 @@
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <pthread.h>
-
-#include "mlogger.h"
-
-pthread_mutex_t mlog_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-char mlog_buffer[MLOG_BUFFER_SIZE];
-int mlog_buffer_allocated_size = 0;
-
-FILE *mlog_output;
-char *mlog_file_name = MLOG_FILE_NAME;
-int mlog_file_size = 0;
-int mlog_file_id = 1;
-
-LOG_LEVEL CUR_LOG_LEVEL = DEFAULT_LOG_LEVEL;
-LOG_LEVEL CUR_FLUSH_LEVEL = DEFAULT_FLUSH_LEVEL;
-
-int MLOG_STOP = FALSE;
-
-
-// Internal error messages in mlogger
-static void _mlog_error(const char *function_name, char *error_msg)
-{
-    fprintf(stderr, "Error in function %s: %s\n", function_name, error_msg);
-    // exit(-1);
-}
-
-
-// Internal info messages in mlogger
-static void _mlog_info(const char *function_name, char *error_msg)
-{
-    fprintf(stderr, "[%s] %s\n", function_name, error_msg);
-}
-
-
-// Check if log file is open
-static void _mlog_file_is_open(void)
-{
-    if(!mlog_output)
-    {
-        _mlog_error(__func__, "The log file is not open");
-        exit(-1);
-    }
-}
-
-
-// Output error from snprintf of vsnprintf
-static void _mlog_log_output_error(int bytes_written)
-{
-    if(bytes_written < 0)
-    {
-        _mlog_error(__func__, "Output error - Returned negative value");
-        exit(-1);
-    }
-}
-
-
-// Prepares a file in order to write the contents of the buffer 
-// when necessary. The file name each time is merovingian_{int}.log
-static void _mlog_create_file(void)
-{
-    char id[INT_MAX_LEN]; 
-    snprintf(id, INT_MAX_LEN, "%d", mlog_file_id);
-
-    char file_name[FILENAME_MAX];
-    sprintf(file_name, "%s%s%s%s", mlog_file_name, "_", id, ".log");
-
-    mlog_output = fopen(file_name, "a+");
-
-    _mlog_file_is_open();
-}
-
-
-// Return the log level as string 
-// static char* _mlog_level_as_string(LOG_LEVEL level)
-// {
-//     switch(level)
-//     {
-//         case M_NONE:
-//             return "NONE";
-//         case M_DEBUG:
-//             return "DEBUG";
-//         case M_INFO:
-//             return "INFO";
-//         case M_WARNING:
-//             return "WARNING";
-//         case M_ERROR:
-//             return "ERROR";
-//         case M_CRITICAL:
-//             return "CRITICAL";
-//     }
-// }
-
-
-static void _mlog_lock()
-{
-    pthread_mutex_lock(&mlog_mutex);
-}
-
-
-static void _mlog_unlock()
-{
-    pthread_mutex_unlock(&mlog_mutex);
-}
-
-
-
-
-
-/**
- * 
- * API CALLS
- * 
- */ 
-void mlog_init(void)
-{
-    _mlog_info(__func__, "Starting mlogger");
-    _mlog_create_file();
-}
-
-
-void mlog_stop(void)
-{
-    MLOG_STOP = TRUE;
-    mlog_flush_buffer();
-    fclose(mlog_output);
-}
-
-
-void mlog_set_log_level(LOG_LEVEL level)
-{
-    if(CUR_LOG_LEVEL != M_NONE && level == M_NONE)
-    {
-        mlog_flush_buffer();
-    }
-
-    _mlog_lock();
-    { 
-        CUR_LOG_LEVEL = level;
-    }
-    _mlog_unlock();
-}
-
-
-void mlog_reset_log_level(void)
-{  
-    if(CUR_LOG_LEVEL != M_NONE)
-    {
-        mlog_flush_buffer();
-    }
-
-    _mlog_lock();
-    { 
-        CUR_LOG_LEVEL = M_NONE;
-    }
-    _mlog_unlock();
-}
-
-
-void mlog_set_flush_level(LOG_LEVEL level)
-{
-    _mlog_lock();
-    { 
-        CUR_FLUSH_LEVEL = level;
-    }
-    _mlog_unlock();
-}
-
-
-void mlog_reset_flush_level(void)
-{
-    _mlog_lock();
-    { 
-        CUR_FLUSH_LEVEL = M_ERROR;
-    }
-    _mlog_unlock();
-}
-
-
-char* mlog_timestamp(void)
-{
-    static char datetime[20];
-    time_t now = time(NULL);
-    struct tm *tmp = localtime(&now);
-    strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tmp);
-
-    return datetime;
-}
-
-
-// TODO -> Rewrite this
-void mlog_log(LOG_LEVEL level, int event_id, const char *fmt, ...)
-{
-    _mlog_file_is_open();
-    
-    if(level >= CUR_LOG_LEVEL && CUR_LOG_LEVEL > M_NONE)
-    {
-        _mlog_lock();
-        
-            va_list va;
-
-            // Calculate the remaining buffer space
-            int buffer_space = MLOG_BUFFER_SIZE - mlog_buffer_allocated_size;
-            int retry_buffer_fill = TRUE;
-
-            // snprintf(char *str, size_t count, ...) -> including null 
terminating character
-            va_start(va, fmt);
-            int bytes_written = vsnprintf(mlog_buffer + 
mlog_buffer_allocated_size, buffer_space, fmt, va);
-            va_end(va);
-
-            _mlog_log_output_error(bytes_written);
-
-            // snprintf returned value -> does not include the null 
terminating character
-            bytes_written++;
-
-            // Message fits the buffer
-            if(bytes_written < buffer_space)
-            {
-                // Increase the current buffer size
-                mlog_buffer_allocated_size += bytes_written;
-                retry_buffer_fill = FALSE;
-            }
-        
-        _mlog_unlock();
-
-
-        // Message did not fit in buffer
-        if(retry_buffer_fill == TRUE)
-        {
-            mlog_flush_buffer();
-
-            _mlog_lock();
-            
-                va_start(va, fmt);
-                bytes_written = vsnprintf(mlog_buffer + 
mlog_buffer_allocated_size, buffer_space, fmt, va);
-                va_end(va);
-                
-                _mlog_log_output_error(bytes_written);
-
-                // Message is too big, to fit the empty buffer
-                // Write it directly to the file
-                if(bytes_written >= buffer_space)
-                {
-                    vfprintf(mlog_output, fmt, va);
-                    fflush(mlog_output);
-                }
-                else 
-                {
-                    // Written to buffer
-                    bytes_written++;
-                    mlog_buffer_allocated_size += bytes_written;
-                }
-            
-            _mlog_unlock();
-        }
-
-        // Flush the buffer in case the event is important depending on the 
flush-level
-        if(event_id >= (int) CUR_FLUSH_LEVEL)
-        {
-            mlog_flush_buffer();
-        }
-    }
-}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to