| 1 |
/* |
| 2 |
* SRT - Secure, Reliable, Transport |
| 3 |
* Copyright (c) 2018 Haivision Systems Inc. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
/***************************************************************************** |
| 12 |
written by |
| 13 |
Haivision Systems Inc. |
| 14 |
*****************************************************************************/ |
| 15 |
|
| 16 |
#ifndef INC_SRT_LOGGING_API_H |
| 17 |
#define INC_SRT_LOGGING_API_H |
| 18 |
|
| 19 |
// These are required for access functions: |
| 20 |
// - adding FA (requires set) |
| 21 |
// - setting a log stream (requires iostream) |
| 22 |
#ifdef __cplusplus |
| 23 |
#include <set> |
| 24 |
#include <iostream> |
| 25 |
#endif |
| 26 |
|
| 27 |
#ifdef _WIN32 |
| 28 |
#include "win/syslog_defs.h" |
| 29 |
#else |
| 30 |
#include <syslog.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
// Syslog is included so that it provides log level names. |
| 34 |
// Haivision log standard requires the same names plus extra one: |
| 35 |
#ifndef LOG_DEBUG_TRACE |
| 36 |
#define LOG_DEBUG_TRACE 8 |
| 37 |
#endif |
| 38 |
// It's unused anyway, just for the record. |
| 39 |
#define SRT_LOG_LEVEL_MIN LOG_CRIT |
| 40 |
#define SRT_LOG_LEVEL_MAX LOG_DEBUG |
| 41 |
|
| 42 |
// Flags |
| 43 |
#define SRT_LOGF_DISABLE_TIME 1 |
| 44 |
#define SRT_LOGF_DISABLE_THREADNAME 2 |
| 45 |
#define SRT_LOGF_DISABLE_SEVERITY 4 |
| 46 |
#define SRT_LOGF_DISABLE_EOL 8 |
| 47 |
|
| 48 |
// Handler type. |
| 49 |
typedef void SRT_LOG_HANDLER_FN(void* opaque, int level, const char* file, int line, const char* area, const char* message); |
| 50 |
|
| 51 |
#ifdef __cplusplus |
| 52 |
namespace srt_logging |
| 53 |
{ |
| 54 |
|
| 55 |
|
| 56 |
struct LogFA |
| 57 |
{ |
| 58 |
private: |
| 59 |
int value; |
| 60 |
public: |
| 61 |
operator int() const { return value; } |
| 62 |
|
| 63 |
LogFA(int v): value(v) |
| 64 |
{ |
| 65 |
// Generally this was what it has to be used for. |
| 66 |
// Unfortunately it couldn't be agreed with the |
| 67 |
//logging_fa_all.insert(v); |
| 68 |
} |
| 69 |
}; |
| 70 |
|
| 71 |
const LogFA LOGFA_GENERAL = 0; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
namespace LogLevel |
| 76 |
{ |
| 77 |
// There are 3 general levels: |
| 78 |
|
| 79 |
// A. fatal - this means the application WILL crash. |
| 80 |
// B. unexpected: |
| 81 |
// - error: this was unexpected for the library |
| 82 |
// - warning: this was expected by the library, but may be harmful for the application |
| 83 |
// C. expected: |
| 84 |
// - note: a significant, but rarely occurring event |
| 85 |
// - debug: may occur even very often and enabling it can harm performance |
| 86 |
|
| 87 |
enum type |
| 88 |
{ |
| 89 |
fatal = LOG_CRIT, |
| 90 |
// Fatal vs. Error: with Error, you can still continue. |
| 91 |
error = LOG_ERR, |
| 92 |
// Error vs. Warning: Warning isn't considered a problem for the library. |
| 93 |
warning = LOG_WARNING, |
| 94 |
// Warning vs. Note: Note means something unusual, but completely correct behavior. |
| 95 |
note = LOG_NOTICE, |
| 96 |
// Note vs. Debug: Debug may occur even multiple times in a millisecond. |
| 97 |
// (Well, worth noting that Error and Warning potentially also can). |
| 98 |
debug = LOG_DEBUG |
| 99 |
}; |
| 100 |
} |
| 101 |
|
| 102 |
class Logger; |
| 103 |
|
| 104 |
} |
| 105 |
#endif |
| 106 |
|
| 107 |
#endif |