| 1 | /********************************************************************** |
|---|
| 2 | * Copyright (c) 2005-2008 David Carter <dcarter@arm4.org> and others. |
|---|
| 3 | * All rights reserved. This program and the accompanying materials |
|---|
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
|---|
| 5 | * which accompanies this distribution, and is available at |
|---|
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
|---|
| 7 | * |
|---|
| 8 | * Contributors: |
|---|
| 9 | * David Carter - Initial API and implementation |
|---|
| 10 | **********************************************************************/ |
|---|
| 11 | |
|---|
| 12 | #ifndef LIBARM4DB_LOGGER_H /* Prevent multiple inclusion */ |
|---|
| 13 | #define LIBARM4DB_LOGGER_H 1 |
|---|
| 14 | |
|---|
| 15 | #include <cstdio> |
|---|
| 16 | #include <cstdlib> |
|---|
| 17 | #include <cstdarg> |
|---|
| 18 | #include <string> |
|---|
| 19 | #include "Arm4dbExceptions.h" |
|---|
| 20 | |
|---|
| 21 | class Logger |
|---|
| 22 | { |
|---|
| 23 | public: |
|---|
| 24 | /* Constructors */ |
|---|
| 25 | |
|---|
| 26 | /* Destructors */ |
|---|
| 27 | virtual ~Logger (); |
|---|
| 28 | |
|---|
| 29 | /* Accessors */ |
|---|
| 30 | static Logger &getLogger (void); // Singleton accessor |
|---|
| 31 | |
|---|
| 32 | /* Mutators */ |
|---|
| 33 | void setFile (FILE *filePtr) { m_filePtr = filePtr; } |
|---|
| 34 | void setFile (const std::string &name); |
|---|
| 35 | void setName (const std::string &name) { m_namePtr = name; } |
|---|
| 36 | |
|---|
| 37 | /* Operations */ |
|---|
| 38 | void log (const char *format, ...) const; |
|---|
| 39 | void error (const char *format, ...) const; // Log the system error number as well |
|---|
| 40 | void exceptionError (const Arm4dbException &e) const; |
|---|
| 41 | void exceptionError (const Arm4dbException &e, const char *format, ...) const; |
|---|
| 42 | |
|---|
| 43 | /* Operators */ |
|---|
| 44 | |
|---|
| 45 | private: |
|---|
| 46 | /* Mark these as private to prevent their use */ |
|---|
| 47 | Logger (); |
|---|
| 48 | Logger (const Logger &); |
|---|
| 49 | Logger &operator= (const Logger &); |
|---|
| 50 | |
|---|
| 51 | void openSyslog (void) const; |
|---|
| 52 | |
|---|
| 53 | static Logger *m_loggerPtr; // Singleton |
|---|
| 54 | FILE *m_filePtr; |
|---|
| 55 | std::string m_namePtr; |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | #endif /* LIBARM4DB_LOGGER_H */ |
|---|
| 59 | |
|---|