summaryrefslogtreecommitdiff
path: root/src/logger.c
blob: 1060eca44890ca2a4efd56a7c8c864271f551925 (plain)
    1 // GPGEdit edits GPG encrypted files
    2 // Copyright (C) 2018  Aaron Ball <nullspoon@oper.io>
    3 //
    4 // This program is free software: you can redistribute it and/or modify
    5 // it under the terms of the GNU General Public License as published by
    6 // the Free Software Foundation, either version 3 of the License, or
    7 // (at your option) any later version.
    8 //
    9 // This program is distributed in the hope that it will be useful,
   10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 // GNU General Public License for more details.
   13 //
   14 // You should have received a copy of the GNU General Public License
   15 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
   16 
   17 #include "logger.h"
   18 
   19 
   20 int _log_level  = LOG_INFO;  // Global log level, set by logger_init().
   21 
   22 
   23 // logger_init:
   24 // Initialize the logger-related variables.
   25 //
   26 // @lvl   Integer representing log level. Use LOG_* macros (eg: LOG_ERROR,
   27 //        LOG_DEBUG, LOG_INFO, etc)
   28 void logger_init(int lvl) {
   29   _log_level  = lvl;
   30 }
   31 
   32 
   33 // logger:
   34 // Logger function. Writes log messages to stdout if specified message level is
   35 // less than or equal to the runtime global log level. Global log level is set
   36 // by logger_init.
   37 //
   38 // @lvl      Integer representing log level
   39 // @format   Format (like printf) of message
   40 // @...      Additional arguments for printf statement.
   41 void logger(int lvl, char* format, ...) {
   42   va_list valist;
   43   va_start(valist, format);
   44 
   45   if(lvl <= _log_level) {
   46     if(lvl == LOG_DEBUG)
   47       printf("DEBUG: ");
   48 
   49     if(lvl == LOG_FATAL)
   50       printf("FATAL: ");
   51 
   52     if(lvl == LOG_ERROR)
   53       printf("ERROR: ");
   54 
   55     if(lvl == LOG_ERROR)
   56       printf("WARN: ");
   57 
   58     vprintf(format, valist);
   59   }
   60 
   61   va_end(valist);
   62 }

Generated by cgit