disk8: Initial commit
[pdp8.git] / sw / disk8 / src / logging.h
diff --git a/sw/disk8/src/logging.h b/sw/disk8/src/logging.h
new file mode 100644 (file)
index 0000000..52381ad
--- /dev/null
@@ -0,0 +1,69 @@
+/* Logging facilities */
+
+/* 
+ * Macros, all printf style:
+ *
+ * ERR(...),  ERROR(...)   - Always printed, errcount is incremented.
+ * WARN(...), WARNING(...) - Printed if verbosity_level>0
+ * MSG(...),  MESSAGE(...), INFO(...)  - Printed if verbosity_level>1
+ * DBG(...),  DEBUG(...)   - Printed if verbosity_level>2
+ * 
+ * Default verbosity level is 1, warnings and errors displayed.
+ */
+
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#include <stdio.h>
+
+/* Global variable containing the program's runtime verbosity level */
+extern int verbosity_level;
+
+/* Global variable containing the program's error count */
+extern int error_count;
+
+/* Global variable containing the program's warning count */
+extern int warn_count;
+
+/* Global variable containing the program's message count */
+extern int msg_count;
+
+/* Show the log summary */
+extern void log_summary();
+
+/* Exit program with logging summary */
+void exit_program(int status);
+
+#define ERROR(...){                            \
+    fprintf(stderr,"  ERROR: " __VA_ARGS__);   \
+    error_count++;                             \
+  }
+
+#define ERR(...) ERROR(__VA_ARGS__)
+
+#define WARNING(...){                          \
+    if (verbosity_level>0) fprintf(stderr,"WARNING: " __VA_ARGS__);    \
+    warn_count++;                                                      \
+  }
+
+#define WARN(...) WARNING(__VA_ARGS__)
+
+#define INFO(...){                             \
+    if (verbosity_level>1) fprintf(stderr, "   INFO: " __VA_ARGS__);   \
+    msg_count++;                                                       \
+  }
+
+#define MESSAGE(...) INFO(__VA_ARGS__)
+
+#define MSG(...) MESSAGE(__VA_ARGS__)
+
+#define DEBUG(...){                                    \
+    if (verbosity_level>2) fprintf(stderr,"  DEBUG: " __VA_ARGS__);\
+  }
+#define DBG(...) DEBUG(__VA_ARGS__)
+
+
+#endif
+
+
+