|
| 1 | +/* |
| 2 | + * Copyright 2022 New Relic Corporation. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +#ifndef NR_LOG_LEVEL_HDR |
| 7 | +#define NR_LOG_LEVEL_HDR |
| 8 | + |
| 9 | +#include <stdbool.h> |
| 10 | + |
| 11 | +/* |
| 12 | + * Implementation Based on: |
| 13 | + * https://www.php-fig.org/psr/psr-3/#5-psrlogloglevel |
| 14 | + * https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1 |
| 15 | + */ |
| 16 | + |
| 17 | +#define LOG_LEVEL_EMERGENCY (0) // system is unusable |
| 18 | +#define LOG_LEVEL_ALERT (1) // action must be taken immediately |
| 19 | +#define LOG_LEVEL_CRITICAL (2) // critical conditions |
| 20 | +#define LOG_LEVEL_ERROR (3) // error conditions |
| 21 | +#define LOG_LEVEL_WARNING (4) // warning conditions |
| 22 | +#define LOG_LEVEL_NOTICE (5) // normal but significant conditions |
| 23 | +#define LOG_LEVEL_INFO (6) // informational messages |
| 24 | +#define LOG_LEVEL_DEBUG (7) // debug-level messages |
| 25 | +#define LOG_LEVEL_UNKNOWN (8) // NON PSR- Unknown/Undefined log level |
| 26 | +#define LOG_LEVEL_DEFAULT (LOG_LEVEL_WARNING) |
| 27 | + |
| 28 | +#define LL_EMER_STR "EMERGENCY" |
| 29 | +#define LL_ALER_STR "ALERT" |
| 30 | +#define LL_CRIT_STR "CRITICAL" |
| 31 | +#define LL_ERRO_STR "ERROR" |
| 32 | +#define LL_WARN_STR "WARNING" |
| 33 | +#define LL_NOTI_STR "NOTICE" |
| 34 | +#define LL_INFO_STR "INFO" |
| 35 | +#define LL_DEBU_STR "DEBUG" |
| 36 | +#define LL_UNKN_STR "UNKNOWN" |
| 37 | + |
| 38 | +/* |
| 39 | + * Purpose : Convert PSR-3 string log level to RFC5424 represenation. |
| 40 | + * |
| 41 | + * Params : 1. str String Log Level |
| 42 | + * |
| 43 | + * Returns : Integer RFC5424 Log Level numerical code |
| 44 | + */ |
| 45 | +extern int nr_log_level_str_to_int(const char* str); |
| 46 | + |
| 47 | +/* |
| 48 | + * Purpose : Convert RFC5424 log level to PSR-3 string represenation. |
| 49 | + * |
| 50 | + * Params : 1. level RFC5424 Log Level |
| 51 | + * |
| 52 | + * Returns : PSR-3 String Log Level as a const char * |
| 53 | + * |
| 54 | + */ |
| 55 | +extern const char* nr_log_level_rfc_to_psr(int level); |
| 56 | + |
| 57 | +#endif /* NR_LOG_LEVEL_HDR */ |
0 commit comments