Home | History | Annotate | Download | only in source
      1 //===-- DNBLog.h ------------------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  Created by Greg Clayton on 6/18/07.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef __DNBLog_h__
     15 #define __DNBLog_h__
     16 
     17 #include <stdio.h>
     18 #include <stdint.h>
     19 #include "DNBDefs.h"
     20 
     21 #ifdef __cplusplus
     22 extern "C" {
     23 #endif
     24 
     25 // Flags that get filled in automatically before calling the log callback function
     26 #define DNBLOG_FLAG_FATAL       (1u << 0)
     27 #define DNBLOG_FLAG_ERROR       (1u << 1)
     28 #define DNBLOG_FLAG_WARNING     (1u << 2)
     29 #define DNBLOG_FLAG_DEBUG       (1u << 3)
     30 #define DNBLOG_FLAG_VERBOSE     (1u << 4)
     31 #define DNBLOG_FLAG_THREADED    (1u << 5)
     32 
     33 #define DNBLOG_ENABLED
     34 
     35 #if defined (DNBLOG_ENABLED)
     36 
     37 #define DNB_EXPORT __attribute__((visibility("default")))
     38 
     39 void        _DNBLog(uint32_t flags, const char *format, ...) __attribute__ ((format (printf, 2, 3))) DNB_EXPORT;
     40 void        _DNBLogDebug (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     41 void        _DNBLogDebugVerbose (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     42 void        _DNBLogThreaded (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     43 void        _DNBLogThreadedIf (uint32_t mask, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))) DNB_EXPORT;
     44 void        _DNBLogError (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     45 void        _DNBLogFatalError (int err, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))) DNB_EXPORT;
     46 void        _DNBLogVerbose (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     47 void        _DNBLogWarning (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     48 void        _DNBLogWarningVerbose (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) DNB_EXPORT;
     49 bool        DNBLogCheckLogBit (uint32_t bit) DNB_EXPORT;
     50 uint32_t    DNBLogSetLogMask (uint32_t mask) DNB_EXPORT;
     51 uint32_t    DNBLogGetLogMask () DNB_EXPORT;
     52 void        DNBLogSetLogCallback (DNBCallbackLog callback, void *baton) DNB_EXPORT;
     53 DNBCallbackLog DNBLogGetLogCallback () DNB_EXPORT;
     54 bool        DNBLogEnabled () DNB_EXPORT;
     55 bool        DNBLogEnabledForAny (uint32_t mask) DNB_EXPORT;
     56 int         DNBLogGetDebug () DNB_EXPORT;
     57 void        DNBLogSetDebug (int g) DNB_EXPORT;
     58 int         DNBLogGetVerbose () DNB_EXPORT;
     59 void        DNBLogSetVerbose (int g) DNB_EXPORT;
     60 
     61 #define     DNBLog(fmt, ...)                    do { if (DNBLogEnabled()) { _DNBLog(0, fmt, ## __VA_ARGS__);                 } } while (0)
     62 #define     DNBLogDebug(fmt, ...)               do { if (DNBLogEnabled()) { _DNBLogDebug(fmt, ## __VA_ARGS__);               } } while (0)
     63 #define     DNBLogDebugVerbose(fmt, ...)        do { if (DNBLogEnabled()) { _DNBLogDebugVerbose(fmt, ## __VA_ARGS__);        } } while (0)
     64 #define     DNBLogThreaded(fmt, ...)            do { if (DNBLogEnabled()) { _DNBLogThreaded(fmt, ## __VA_ARGS__);            } } while (0)
     65 #define     DNBLogThreadedIf(mask, fmt, ...)    do { if (DNBLogEnabledForAny(mask)) { _DNBLogThreaded(fmt, ## __VA_ARGS__);  } } while (0)
     66 #define     DNBLogError(fmt, ...)               do { if (DNBLogEnabled()) { _DNBLogError(fmt, ## __VA_ARGS__);               } } while (0)
     67 #define     DNBLogFatalError(err, fmt, ...)     do { if (DNBLogEnabled()) { _DNBLogFatalError(err, fmt, ## __VA_ARGS__);     } } while (0)
     68 #define     DNBLogVerbose(fmt, ...)             do { if (DNBLogEnabled()) { _DNBLogVerbose(fmt, ## __VA_ARGS__);             } } while (0)
     69 #define     DNBLogWarning(fmt, ...)             do { if (DNBLogEnabled()) { _DNBLogWarning(fmt, ## __VA_ARGS__);             } } while (0)
     70 #define     DNBLogWarningVerbose(fmt, ...)      do { if (DNBLogEnabled()) { _DNBLogWarningVerbose(fmt, ## __VA_ARGS__);      } } while (0)
     71 
     72 #else   // #if defined(DNBLOG_ENABLED)
     73 
     74 #define     DNBLogDebug(...)            ((void)0)
     75 #define     DNBLogDebugVerbose(...)     ((void)0)
     76 #define     DNBLogThreaded(...)         ((void)0)
     77 #define     DNBLogThreadedIf(...)       ((void)0)
     78 #define     DNBLogError(...)            ((void)0)
     79 #define     DNBLogFatalError(...)       ((void)0)
     80 #define     DNBLogVerbose(...)          ((void)0)
     81 #define     DNBLogWarning(...)          ((void)0)
     82 #define     DNBLogWarningVerbose(...)   ((void)0)
     83 #define     DNBLogGetLogFile()          ((FILE *)NULL)
     84 #define     DNBLogSetLogFile(f)         ((void)0)
     85 #define     DNBLogCheckLogBit(bit)      ((bool)false)
     86 #define     DNBLogSetLogMask(mask)      ((uint32_t)0u)
     87 #define     DNBLogGetLogMask()          ((uint32_t)0u)
     88 #define     DNBLogToASL()               ((void)0)
     89 #define     DNBLogToFile()              ((void)0)
     90 #define     DNBLogCloseLogFile()        ((void)0)
     91 
     92 #endif // #else defined(DNBLOG_ENABLED)
     93 
     94 #ifdef __cplusplus
     95 }
     96 #endif
     97 
     98 #endif // #ifndef __DNBLog_h__
     99