/work/include/jasper/jas_log.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2001-2002 Michael David Adams. |
3 | | * All rights reserved. |
4 | | */ |
5 | | |
6 | | /* __START_OF_JASPER_LICENSE__ |
7 | | * |
8 | | * JasPer License Version 2.0 |
9 | | * |
10 | | * Copyright (c) 2001-2006 Michael David Adams |
11 | | * Copyright (c) 1999-2000 Image Power, Inc. |
12 | | * Copyright (c) 1999-2000 The University of British Columbia |
13 | | * |
14 | | * All rights reserved. |
15 | | * |
16 | | * Permission is hereby granted, free of charge, to any person (the |
17 | | * "User") obtaining a copy of this software and associated documentation |
18 | | * files (the "Software"), to deal in the Software without restriction, |
19 | | * including without limitation the rights to use, copy, modify, merge, |
20 | | * publish, distribute, and/or sell copies of the Software, and to permit |
21 | | * persons to whom the Software is furnished to do so, subject to the |
22 | | * following conditions: |
23 | | * |
24 | | * 1. The above copyright notices and this permission notice (which |
25 | | * includes the disclaimer below) shall be included in all copies or |
26 | | * substantial portions of the Software. |
27 | | * |
28 | | * 2. The name of a copyright holder shall not be used to endorse or |
29 | | * promote products derived from the Software without specific prior |
30 | | * written permission. |
31 | | * |
32 | | * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS |
33 | | * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER |
34 | | * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS |
35 | | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
36 | | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
37 | | * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO |
38 | | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
39 | | * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
40 | | * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
41 | | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
42 | | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE |
43 | | * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE |
44 | | * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. |
45 | | * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS |
46 | | * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL |
47 | | * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS |
48 | | * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE |
49 | | * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE |
50 | | * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL |
51 | | * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, |
52 | | * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL |
53 | | * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH |
54 | | * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, |
55 | | * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH |
56 | | * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY |
57 | | * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. |
58 | | * |
59 | | * __END_OF_JASPER_LICENSE__ |
60 | | */ |
61 | | |
62 | | /*! |
63 | | * @file jas_log.h |
64 | | * @brief JasPer Logging Functionality |
65 | | */ |
66 | | |
67 | | #ifndef JAS_LOG_H |
68 | | #define JAS_LOG_H |
69 | | |
70 | | /******************************************************************************\ |
71 | | * Includes. |
72 | | \******************************************************************************/ |
73 | | |
74 | | /* The configuration header file should be included first. */ |
75 | | #include <jasper/jas_config.h> |
76 | | |
77 | | #include <stdio.h> |
78 | | #include <stdarg.h> |
79 | | |
80 | | #ifdef __cplusplus |
81 | | extern "C" { |
82 | | #endif |
83 | | |
84 | | /*! |
85 | | * @addtogroup module_log |
86 | | * @{ |
87 | | */ |
88 | | |
89 | | /******************************************************************************\ |
90 | | * Macros and functions. |
91 | | \******************************************************************************/ |
92 | | |
93 | | /*! Log type class for unclassified messages. */ |
94 | | #define JAS_LOGTYPE_CLASS_NULL 0 |
95 | | /*! Log type class for errors. */ |
96 | | #define JAS_LOGTYPE_CLASS_ERROR 1 |
97 | | /*! Log type class for warnings. */ |
98 | | #define JAS_LOGTYPE_CLASS_WARN 2 |
99 | | /*! Log type class for informational messages. */ |
100 | | #define JAS_LOGTYPE_CLASS_INFO 3 |
101 | | /*! Log type class for debugging messages. */ |
102 | | #define JAS_LOGTYPE_CLASS_DEBUG 4 |
103 | | #define JAS_LOGTYPE_NUM_CLASSES 5 |
104 | | |
105 | | #define JAS_LOGTYPE_MAX_PRIORITY 16384 |
106 | | |
107 | | // NOTE: without the @struct, jas_logtype_t autolinks are not generated |
108 | | /*! |
109 | | @struct jas_logtype_t |
110 | | @brief Type used for the log type. |
111 | | */ |
112 | | typedef unsigned int jas_logtype_t; |
113 | | |
114 | | /*! |
115 | | @brief Type used for formatted message logging function. |
116 | | */ |
117 | | typedef int (jas_vlogmsgf_t)(jas_logtype_t, const char *, va_list); |
118 | | |
119 | | /*! |
120 | | @brief Create an instance of a logtype. |
121 | | */ |
122 | | static inline jas_logtype_t jas_logtype_init(int clas, int priority) |
123 | 0 | { |
124 | 0 | assert(clas >= 0 && clas < JAS_LOGTYPE_NUM_CLASSES); |
125 | 0 | assert(priority >= 0 && priority <= JAS_LOGTYPE_MAX_PRIORITY); |
126 | 0 | return (clas & 0xf) | (priority << 4); |
127 | 0 | } |
128 | | |
129 | | /*! |
130 | | @brief Get the class of a logtype. |
131 | | */ |
132 | | static inline int jas_logtype_getclass(jas_logtype_t type) |
133 | 0 | { |
134 | 0 | return type & 0xf; |
135 | 0 | } |
136 | | |
137 | | /*! |
138 | | @brief Get the priority of a logtype. |
139 | | */ |
140 | | static inline int jas_logtype_getpriority(jas_logtype_t type) |
141 | 0 | { |
142 | 0 | return type >> 4; |
143 | 0 | } |
144 | | |
145 | | /*! |
146 | | @brief Print formatted log message. |
147 | | */ |
148 | | JAS_EXPORT |
149 | | int jas_vlogmsgf(jas_logtype_t type, const char *fmt, va_list ap); |
150 | | |
151 | | /*! |
152 | | @brief Output a log message to standard error. |
153 | | */ |
154 | | JAS_EXPORT |
155 | | int jas_vlogmsgf_stderr(jas_logtype_t type, const char *fmt, va_list ap); |
156 | | |
157 | | /*! |
158 | | @brief Output a log message to nowhere (i.e., discard the message). |
159 | | */ |
160 | | JAS_EXPORT |
161 | | int jas_vlogmsgf_discard(jas_logtype_t type, const char *fmt, va_list ap); |
162 | | |
163 | | /*! |
164 | | * @} |
165 | | */ |
166 | | |
167 | | #ifdef __cplusplus |
168 | | } |
169 | | #endif |
170 | | |
171 | | #endif |