FEATURE: library logger

Mechanism for logging messages and setting library specific errno.
diff --git a/src/common.c b/src/common.c
new file mode 100644
index 0000000..e863200
--- /dev/null
+++ b/src/common.c
@@ -0,0 +1,27 @@
+/**
+ * @file common.c
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @brief common libyang routines implementations
+ *
+ * Copyright (c) 2015 CESNET, z.s.p.o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of the Company nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ */
+
+#include "common.h"
+
+/*
+ * libyang errno
+ */
+int ly_errno = 0;
diff --git a/src/common.h b/src/common.h
index 140dd78..6b1a451 100644
--- a/src/common.h
+++ b/src/common.h
@@ -22,11 +22,32 @@
 #ifndef LY_COMMON_H_
 #define LY_COMMON_H_
 
+#include <stdint.h>
+
+#include "libyang.h"
+
 #ifdef __GNUC__
 #  define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
 #else
 #  define UNUSED(x) UNUSED_ ## x
 #endif
 
+/*
+ * logger
+ */
+extern volatile uint8_t ly_verb_level;
+void ly_log(LY_VERB_LEVEL level, int errno_, const char *format, ...);
+#define LY_ERR(errno,str,args...) ly_log(LY_VERB_ERR,errno,str,##args)
+#define LY_WRN(format,args...) if(ly_verb_level>=LY_VERB_WRN){ly_log(LY_VERB_WRN,format,##args);}
+#define LY_VRB(format,args...) if(ly_verb_level>=LY_VERB_VRB){ly_log(LY_VERB_VRB,format,##args);}
+#define LY_DBG(format,args...) if(ly_verb_level>=LY_VERB_DBG){ly_log(LY_VERB_DBG,format,##args);}
+
+/*
+ * libyang's errno
+ */
+extern int ly_errno;
+
+#define	LY_EINVAL   1 /* Invalid argument */
+
 
 #endif /* LY_COMMON_H_ */
diff --git a/src/libyang.h b/src/libyang.h
new file mode 100644
index 0000000..36153a1
--- /dev/null
+++ b/src/libyang.h
@@ -0,0 +1,60 @@
+/**
+ * @file common.h
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @brief common definitions for libyang
+ *
+ * Copyright (c) 2015 CESNET, z.s.p.o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of the Company nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ */
+
+#ifndef LY_LIBYANG_H_
+#define LY_LIBYANG_H_
+
+/**
+ * @page howto How To ...
+ *
+ * - @subpage howtologger
+ */
+
+/**
+ * @defgroup logger libyang logger
+ *
+ * @page howtologger Logger
+ *
+ * There are 4 verbosity levels defined as ::LY_VERB_LEVEL. The level can be
+ * changed by the ly_verbosity() function. By default, the verbosity level is
+ * set to #LY_VERB_ERR value;
+ *
+ */
+
+/**
+ * @typedef LY_VERB_LEVEL
+ * @brief Verbosity levels.
+ * @ingroup logger
+ */
+typedef enum {
+	LY_VERB_ERR,  /**< Print only error messages. */
+	LY_VERB_WRN,  /**< Print error and warning messages. */
+	LY_VERB_VRB,  /**< Besides errors and warnings, print some other verbose messages. */
+	LY_VERB_DBG   /**< Print all messages including some development debug messages. */
+} LY_VERB_LEVEL;
+
+/**
+ *
+ */
+void ly_verbosity(LY_VERB_LEVEL level);
+
+
+#endif /* LY_LIBYANG_H_ */
diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..c690857
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,59 @@
+/**
+ * @file log.c
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @brief libyang logger implementation
+ *
+ * Copyright (c) 2015 CESNET, z.s.p.o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of the Company nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ */
+
+#define _BSD_SOURCE
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "common.h"
+
+volatile uint8_t ly_verb_level = LY_VERB_ERR;
+
+void ly_verbosity(LY_VERB_LEVEL level)
+{
+	ly_verb_level = level;
+}
+
+static void log_vprintf(LY_VERB_LEVEL level, const char *format, va_list args)
+{
+#define PRV_MSG_SIZE 4096
+	char prv_msg[PRV_MSG_SIZE];
+
+	vsnprintf(prv_msg, PRV_MSG_SIZE - 1, format, args);
+	prv_msg[PRV_MSG_SIZE - 1] = '\0';
+	fprintf(stderr, "libyang[%d]: %s\n", level, prv_msg);
+#undef PRV_MSG_SIZE
+}
+
+void ly_log(LY_VERB_LEVEL level, int errno_, const char *format, ...)
+{
+	va_list ap;
+
+	if (level == LY_VERB_ERR) {
+		ly_errno = errno_;
+	}
+
+	if (format) {
+		va_start(ap, format);
+		log_vprintf(level, format, ap);
+		va_end(ap);
+	}
+}