libdigidocpp
log.h
Go to the documentation of this file.
1 /*
2  * libdigidocpp
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #pragma once
21 
22 #include "Exports.h"
23 
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <iostream>
27 
28 namespace digidoc
29 {
31  {
32  public:
33  enum LogType
34  {
35  ErrorType = 0,
38  DebugType
39  };
40 
41  static std::string format(const char *fmt, ...);
42  static void out(LogType type, const char *file, unsigned int line, const char *format, ...);
43  static void dbgPrintfMemImpl(const char *msg, const void *ptr, size_t size, const char *file, int line);
44 
45  private:
46  static std::string formatArgList(const char *fmt, va_list args);
47  };
48 }
49 
50 #define ERR(...) digidoc::Log::out(digidoc::Log::ErrorType, __FILE__, __LINE__, __VA_ARGS__)
51 #define WARN(...) digidoc::Log::out(digidoc::Log::WarnType, __FILE__, __LINE__, __VA_ARGS__)
52 #define INFO(...) digidoc::Log::out(digidoc::Log::InfoType, __FILE__, __LINE__, __VA_ARGS__)
53 #define DEBUG(...) digidoc::Log::out(digidoc::Log::DebugType, __FILE__, __LINE__, __VA_ARGS__)
54 #define DEBUG2(FILE,LINE,...) digidoc::Log::out(digidoc::Log::DebugType, FILE, LINE, __VA_ARGS__)
55 #define DEBUGMEM(msg, ptr, size) digidoc::Log::dbgPrintfMemImpl(msg, ptr, size, __FILE__, __LINE__)
56 
57 #define VER_STR_HELPER(x) #x
58 #define VER_STR(x) VER_STR_HELPER(x)
59 #define FILE_VER MAJOR_VER,MINOR_VER,RELEASE_VER,BUILD_VER
60 #define FILE_VER_STR VER_STR(MAJOR_VER.MINOR_VER.RELEASE_VER.BUILD_VER) "\0"
61 
62 #define THROW_BDOCEXCEPTION(...) throw BDocException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__))
63 #define THROW_BDOCEXCEPTION_CAUSE(_cause, ...) throw BDocException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__), _cause)
64 #define THROW_IOEXCEPTION(...) throw IOException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__))
65 #define THROW_OCSPEXCEPTION(rsc, ...) throw OCSPException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__), rsc)
66 #define THROW_SIGNEXCEPTION(...) throw SignException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__))
67 #define THROW_SIGNEXCEPTION_CAUSE(_cause, ...) throw SignException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__), _cause)
68 #define THROW_SIGNATUREEXCEPTION(...) throw SignatureException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__))
69 #define THROW_SIGNATUREEXCEPTION_CAUSE(_cause, ...) throw SignatureException(__FILE__, __LINE__, digidoc::Log::format(__VA_ARGS__), _cause)