All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Member Functions
GpCoreTools::Log Class Reference

Brief description of class still missing. More...

#include <Log.h>

List of all members.

Public Member Functions

 Log (FILE *stream=0)
void setFile (const char *fileName)
 ~Log ()

Static Public Member Functions

static void setVerbosity (int v)
static FILE * stream ()
static void timeStamp (char *buffer32)
static int verbosity ()
static void write (int level, const char *cformat,...)
static void writeNoMutex (int level, const char *cformat,...)
static void writeNoStamp (int level, const char *cformat,...)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

GpCoreTools::Log::Log ( FILE *  stream = 0)

Init log to stream. If null, the default stderr is not changed.

References GpCoreTools::CoreApplication::instance(), and stream().

{
#ifdef SYSLOG
  openlog (CoreApplication::instance()->applicationName(), LOG_NDELAY | LOG_PID, LOG_DAEMON);
#else
  if(stream) {
    _stream=stream;
  }
#endif
}

Description of destructor still missing

{
#ifdef SYSLOG
  closelog();
#else
  if(_stream!=stderr && _stream!=stdin) {
    fclose(_stream);
  }
#endif
}

Member Function Documentation

void GpCoreTools::Log::setFile ( const char *  fileName)

Description of constructor still missing

References write().

Referenced by main().

{
#ifndef SYSLOG
  if(!fileName) {
    return;
  }
  if(_stream!=stderr && _stream!=stdin) {
    fclose(_stream);
  }

  int fd=open(fileName, O_WRONLY | O_NONBLOCK | O_CREAT | O_APPEND, S_IRWXU | S_IRGRP | S_IROTH);
  if(fd>=0) {
    _stream=fdopen(fd, "a");
    assert(_stream);
  } else {
    _stream=stderr;
    write(0, "failed to open log file %s\n",fileName);
  }
#endif
}
static void GpCoreTools::Log::setVerbosity ( int  v) [inline, static]

Referenced by GpCoreTools::CoreApplication::CoreApplication().

{_verbosity=v;}
static FILE* GpCoreTools::Log::stream ( ) [inline, static]
void GpCoreTools::Log::timeStamp ( char *  buffer32) [static]

Referenced by write(), and writeNoMutex().

{
  time_t t=time(0);
  strftime(buffer32, 32, "%a %b %d %H:%M:%S %Y: ", gmtime(&t));
}
static int GpCoreTools::Log::verbosity ( ) [inline, static]
{return _verbosity;}
void GpCoreTools::Log::write ( int  level,
const char *  cformat,
  ... 
) [static]
void GpCoreTools::Log::writeNoMutex ( int  level,
const char *  cformat,
  ... 
) [static]

Used only when no mutex can be used, for instance during signaled exceptions.

References timeStamp().

Referenced by GpCoreTools::DaemonApplication::childInterrupted().

{
  if(level<=_verbosity) {
    va_list argptr;
    va_start(argptr, cformat);
#ifdef SYSLOG
    vsyslog(LOG_INFO, cformat, argptr);
#else
    // Print time stamp
    char timeBuf[32];
    timeStamp(timeBuf);
    unsigned int n=strlen(timeBuf);
    // Print message
    if(fwrite(timeBuf, 1, n, _stream)==n) {
      vfprintf(_stream, cformat, argptr);
      fflush(_stream);
    }
#endif
    va_end(argptr);
  }
}
void GpCoreTools::Log::writeNoStamp ( int  level,
const char *  cformat,
  ... 
) [static]

Referenced by GpCoreTools::CoreApplication::osSignal().

{
  if(level<=_verbosity) {
    va_list argptr;
    va_start(argptr, cformat);
#ifdef SYSLOG
    vsyslog(LOG_INFO, cformat, argptr);
#else
    // Print message
    pthread_mutex_lock(&_mutex);
    vfprintf(_stream, cformat, argptr);
    fflush(_stream);
    pthread_mutex_unlock(&_mutex);
#endif
    va_end(argptr);
  }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines