y2log.cc File Reference

#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits>
#include <list>
#include "y2util/y2log.h"
#include "y2util/miniini.h"
#include "y2util/stringutil.h"
#include "y2util/PathInfo.h"
#include <syslog.h>

Classes

class  LogTail::Impl

Defines

#define _GNU_SOURCE   1
#define Y2LOG_DATE   "%Y-%m-%d %H:%M:%S"
#define Y2LOG_COMMON   "%s %s%s:%d %s%s"
#define Y2LOG_SIMPLE   "%2$s%3$s:%4$d %1$s %5$s%6$s"
#define Y2LOG_FORMAT   "%s <%d> %s(%d)"
#define Y2LOG_SYSLOG   "<%d>%s"
#define Y2LOG_MAXSIZE   10* 1024 * 1024
#define Y2LOG_MAXNUM   10
#define LOGDIR   "/var/log/YaST2"
#define Y2LOG_ROOT   LOGDIR "/y2log"
#define Y2LOG_USER   "/.y2log"
#define Y2LOG_FALLBACK   "/y2log"
#define Y2LOG_CONF   "log.conf"
#define Y2LOG_VAR_DEBUG   "Y2DEBUG"
#define Y2LOG_VAR_ALL   "Y2DEBUGALL"
#define Y2LOG_VAR_ONCRASH   "Y2DEBUGONCRASH"
#define Y2LOG_VAR_SIZE   "Y2MAXLOGSIZE"
#define Y2LOG_VAR_NUM   "Y2MAXLOGNUM"
#define Y2LOG_FACILITY   "yast2"

Functions

static void do_log_syslog (const char *logmessage)
static void do_log_yast (const char *logmessage)
static void shift_log_files (string filename)
static int dup_stderr ()
static FILE * open_logfile ()
void y2_logger_function (loglevel_t level, const char *component, const char *file, const int line, const char *func, const char *format,...)
void y2_logger_blanik (loglevel_t level, const char *component, const char *file, const int line, const char *func, const char *format,...)
string y2_logfmt_common (bool simple, const char *component, const char *file, const int line, const char *function, const char *format, va_list ap)
string y2_logfmt_prefix (loglevel_t level)
void y2_vlogger_function (loglevel_t level, const char *component, const char *file, const int line, const char *function, const char *format, va_list ap)
void y2_vlogger_blanik (loglevel_t level, const char *component, const char *file, const int line, const char *function, const char *format, va_list ap)
void y2_logger_raw (const char *logmessage)
void set_log_filename (string fname)
string get_log_filename ()
static string old (const string &filename, int i, const char *suffix)
static void signal_handler (int signum)
static void set_signal_handler (int signum)
void set_log_conf (string confname)
bool should_be_logged (int loglevel, string componentname)
void set_log_simple_mode (bool simple)
void set_log_debug (bool on)
bool get_log_debug ()
bool should_be_buffered ()

Variables

inisection logconf
static bool did_set_logname = false
static sig_atomic_t did_read_logconf = 0
static const char * logname
static off_t maxlogsize
static int maxlognum
static sig_atomic_t log_debug = false
static bool log_to_file = true
static bool log_to_syslog = false
static bool log_all_variable = false
static bool log_simple = false
static FILE * Y2LOG_STDERR = stderr
static const char * log_messages []
static int variable_not_used = dup_stderr()
LogTail blanik = LogTail ()

Define Documentation

#define _GNU_SOURCE   1

#define LOGDIR   "/var/log/YaST2"

#define Y2LOG_COMMON   "%s %s%s:%d %s%s"

Referenced by y2_logfmt_common().

#define Y2LOG_CONF   "log.conf"

Referenced by set_log_conf().

#define Y2LOG_DATE   "%Y-%m-%d %H:%M:%S"

Referenced by y2_logfmt_prefix().

#define Y2LOG_FACILITY   "yast2"

#define Y2LOG_FALLBACK   "/y2log"

Referenced by set_log_filename().

#define Y2LOG_FORMAT   "%s <%d> %s(%d)"

Referenced by y2_logfmt_prefix().

#define Y2LOG_MAXNUM   10

Referenced by set_log_filename().

#define Y2LOG_MAXSIZE   10* 1024 * 1024

Referenced by set_log_filename().

#define Y2LOG_ROOT   LOGDIR "/y2log"

Referenced by set_log_filename().

#define Y2LOG_SIMPLE   "%2$s%3$s:%4$d %1$s %5$s%6$s"

Referenced by y2_logfmt_common().

#define Y2LOG_SYSLOG   "<%d>%s"

Referenced by y2_vlogger_function().

#define Y2LOG_USER   "/.y2log"

Referenced by set_log_filename().

#define Y2LOG_VAR_ALL   "Y2DEBUGALL"

Referenced by set_log_conf().

#define Y2LOG_VAR_DEBUG   "Y2DEBUG"

Referenced by set_log_conf().

#define Y2LOG_VAR_NUM   "Y2MAXLOGNUM"

Referenced by set_log_filename().

#define Y2LOG_VAR_ONCRASH   "Y2DEBUGONCRASH"

Referenced by should_be_buffered().

#define Y2LOG_VAR_SIZE   "Y2MAXLOGSIZE"

Referenced by set_log_filename().


Function Documentation

static void do_log_syslog ( const char *  logmessage  )  [static]

Referenced by y2_logger_raw().

static void do_log_yast ( const char *  logmessage  )  [static]

static int dup_stderr (  )  [static]

y2log must use a private copy of stderr, esp. in case we're always logging to it (option "-l -"). Some classes like liby2(ExternalProgram) redirect stderr in order to redirect an external programs error output. As a side effect y2log output done after the redirection would show up in the external programs output file instead of yast2's stderr.

References Y2LOG_STDERR.

bool get_log_debug (  ) 

whether debug logging is enabled

References log_debug.

string get_log_filename (  ) 

Logfile name reporting

References did_set_logname, logname, and set_log_filename().

static string old ( const string &  filename,
int  i,
const char *  suffix 
) [static]

Referenced by shift_log_files().

static FILE* open_logfile (  )  [static]

void set_log_conf ( string  confname  ) 

void set_log_debug ( bool  on = true  ) 

enable or disable debug logging

Parameters:
on true for on

References log_debug.

void set_log_filename ( string  fname  ) 

void set_log_simple_mode ( bool  simple  ) 

Set (or reset) the simple mode

References log_simple.

Referenced by main().

static void set_signal_handler ( int  signum  )  [static]

References signal_handler().

Referenced by set_log_conf().

static void shift_log_files ( string  filename  )  [static]

Maintain logfiles We do all of this ourselves because during the installation logrotate does not run

References maxlognum, maxlogsize, and old().

Referenced by do_log_yast().

bool should_be_buffered (  ) 

Should we bother evaluating the arguments to the buffering function?

References Y2LOG_VAR_ONCRASH.

bool should_be_logged ( int  loglevel,
string  componentname 
)

static void signal_handler ( int  signum  )  [static]

Signal handler: re-read log configuration The variable is checked in the main logger function

References did_read_logconf, and log_debug.

string y2_logfmt_common ( bool  simple,
const char *  component,
const char *  file,
const int  line,
const char *  function,
const char *  format,
va_list  ap 
)

Formats the common part

References Y2LOG_COMMON, and Y2LOG_SIMPLE.

Referenced by y2_vlogger_blanik(), and y2_vlogger_function().

string y2_logfmt_prefix ( loglevel_t  level  ) 

References Y2LOG_DATE, and Y2LOG_FORMAT.

Referenced by y2_vlogger_blanik(), and y2_vlogger_function().

void y2_logger_blanik ( loglevel_t  level,
const char *  component,
const char *  file,
const int  line,
const char *  func,
const char *  format,
  ... 
)

References y2_vlogger_blanik().

void y2_logger_function ( loglevel_t  level,
const char *  component,
const char *  file,
const int  line,
const char *  func,
const char *  format,
  ... 
)

The universal logger function

References y2_vlogger_function().

void y2_logger_raw ( const char *  logmessage  ) 

void y2_vlogger_blanik ( loglevel_t  level,
const char *  component,
const char *  file,
const int  line,
const char *  function,
const char *  format,
va_list  ap 
)

void y2_vlogger_function ( loglevel_t  level,
const char *  component,
const char *  file,
const int  line,
const char *  function,
const char *  format,
va_list  ap 
)


Variable Documentation

sig_atomic_t did_read_logconf = 0 [static]

bool did_set_logname = false [static]

bool log_all_variable = false [static]

Referenced by set_log_conf(), and should_be_logged().

sig_atomic_t log_debug = false [static]

const char* log_messages[] [static]

Initial value:

 {
    "debug",
    "milestone",
    "warning",
    "error",
    "error",
    "error",
    "error",
}

bool log_simple = false [static]

bool log_to_file = true [static]

bool log_to_syslog = false [static]

Referenced by set_log_conf(), and should_be_logged().

const char* logname [static]

int maxlognum [static]

off_t maxlogsize [static]

int variable_not_used = dup_stderr() [static]

FILE* Y2LOG_STDERR = stderr [static]


Generated on a sunny day for yast2-core by doxygen 1.5.9