/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : Syslog.h                                                      */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _SYSLOG_H
#define _SYSLOG_H

#include <stdio.h>
#include <stdarg.h>
#include "ourTypes.h"

/*
CLASS 
Syslog

DESCRIPTION
Writes messages to stdout/stderr, and to the "system" log file.
This is a "singleton", so has no public constructor. All public
methods are static.

AUTHOR
Tom O'Reilly
*/
class Syslog {

public:

  ///////////////////////////////////////////////////////////////////
  // Write message to stderr/log
  static void write(const char *msg, ...);

  static int dumpHex( const char *header, const char *msg, unsigned int len );


protected:

  ///////////////////////////////////////////////////////////////////
  // Constructor
  Syslog();

  ///////////////////////////////////////////////////////////////////
  // Destructor
  ~Syslog();

  ///////////////////////////////////////////////////////////////////
  // Write message to stderr
  void writeMsg(const char *msg, va_list args);

  ///////////////////////////////////////////////////////////////////
  // Singleton instance
  static Syslog *instance();

  ///////////////////////////////////////////////////////////////////
  // Create auxillary log file for this process. Must be called 
  // before firstcall to write() method.
  static void createAuxLogFile();

private:

  // Close aux log file on receipt of termination signal
  static void signalHandler(int signalNo);

  // Log file which appears in log directory for individual AUV run
  FILE *_auxLogFile;

  // Singleton instance
  static Syslog *_instance;

  // Flag to create auxillary log file
  static Boolean _createAuxLogFile;
};


#endif
