]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blobdiff - src/log.h
src/: Move log related functions/defines to log.[hc].
[tlsproxy/tlsproxy.git] / src / log.h
diff --git a/src/log.h b/src/log.h
new file mode 100644 (file)
index 0000000..e129e9f
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,47 @@
+/*
+ * Log related functions/defines.
+ *
+ * Copyright (C) 2011  Simon Ruderich
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+/* Log level constants. */
+#define LOG_ERROR   0
+#define LOG_WARNING 1
+#define LOG_DEBUG   2
+
+/* Helper macro for LOG/LOG_PERROR. Print file/line number if compiled with
+ * debug output. */
+#ifdef DEBUG
+#define LOG_PRINT_LOCATION fprintf(stdout, "%s:%-3d ", __FILE__, __LINE__);
+#else
+#define LOG_PRINT_LOCATION
+#endif
+/* Call log_message() and print current file and line number. */
+#define LOG \
+    LOG_PRINT_LOCATION \
+    log_message
+/* perror() replacement with debug level support. */
+#define LOG_PERROR(level, message) \
+    LOG_PRINT_LOCATION \
+    log_message(level, "%s: %s", message, strerror(errno))
+
+
+void log_message(int level, const char *format, ...);
+
+#endif