Allow user programme to set RMR verbosity level

This change centralises the writing of messages to the standard
error device which allows the user programme to have control over
the verbosity level.  Introduces the new rmr_set_vlevel() function.

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I0c4b4b3af94d34b480622ec1f65a9da65cabf2b5
diff --git a/test/logging_test.c b/test/logging_test.c
new file mode 100644
index 0000000..dfc019d
--- /dev/null
+++ b/test/logging_test.c
@@ -0,0 +1,97 @@
+// : vim ts=4 sw=4 noet :
+/*
+==================================================================================
+	    Copyright (c) 2019-2020 Nokia
+	    Copyright (c) 2018-2020 AT&T Intellectual Property.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+	   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================================
+*/
+
+
+/*
+	Mnemonic:	symtab_test.c
+	Abstract:	This is the unit test module that will drive tests against
+				the symbol table portion of RMr.  Run with:
+					ksh unit_test.ksh symtab_test.c
+	Date:		1 April 2019
+	Author: 	E. Scott Daniels
+*/
+
+#define NO_DUMMY_RMR 1			// no dummy rmr functions; we don't pull in rmr.h or agnostic.h
+
+#include "rmr_logging.h"
+#include "logging.c"
+#include "test_support.c"
+
+/*
+	Logging can be difficult to verify as stderr needs to be captured and examined.
+	We will verify internally what we can, and drive logging functions for coverage.
+*/
+int main( ) {
+	int llevel = 99;
+	int errors = 0;
+
+	setenv( "RMR_HR_LOG", "1", 1 );			// drive for coverage in init
+	setenv( "RMR_LOG_VLEVEL", "90", 1 );	// force test for out of range during init
+
+	rmr_vlog( RMR_VL_CRIT, "debug message should not be written\n" );		// force coverage with init call 
+
+	llevel = rmr_vlog_init( );
+	errors += fail_if_equal( llevel, 99, "llevel was not reset by vlog init" );
+	errors += fail_if_equal( llevel, 90, "vlog init did not catch out of range vlog" );
+
+	llevel = 99;
+	setenv( "RMR_LOG_VLEVEL", "-10", 1 );	// force test for out of range during init
+	llevel = rmr_vlog_init( );
+	errors += fail_if_equal( llevel, 99, "neg llevel was not reset by vlog init" );
+	errors += fail_if_equal( llevel, -10, "vlog init did not catch out of range (neg) vlog" );
+
+	rmr_set_vlevel( 2 );
+	
+	rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" );
+	rmr_vlog( RMR_VL_INFO, "info message should not be written\n" );
+	rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" );
+	rmr_vlog( RMR_VL_ERR, "error message should be written\n" );
+	rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" );
+	
+	rmr_set_vlevel( 5 );
+	rmr_vlog( RMR_VL_DEBUG, "debug message should be written\n" );
+	rmr_vlog( RMR_VL_INFO, "info message should be written\n" );
+	rmr_vlog( RMR_VL_WARN, "warn message should be written\n" );
+	rmr_vlog( RMR_VL_ERR, "error message should be written\n" );
+	rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" );
+	
+	rmr_set_vlevel( 0 );
+	rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" );
+	rmr_vlog( RMR_VL_INFO, "info message should not be written\n" );
+	rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" );
+	rmr_vlog( RMR_VL_ERR, "error message should not be written\n" );
+	rmr_vlog( RMR_VL_CRIT, "crit message should not be written\n" );
+
+	rmr_set_vlevel( 1 );
+	rmr_vlog_force( RMR_VL_DEBUG, "debug forced message should be written\n" );
+	rmr_vlog_force( RMR_VL_INFO, "info forced message should be written\n" );
+	rmr_vlog_force( RMR_VL_WARN, "warn forced message should be written\n" );
+	rmr_vlog_force( RMR_VL_ERR, "error forced message should be written\n" );
+	rmr_vlog_force( RMR_VL_CRIT, "crit forced message should be written\n" );
+
+
+	rmr_vlog( -1, "out of range message might be written\n" );			// drive range checks
+	rmr_vlog( 10, "out of range message should not be written\n" );
+
+	rmr_vlog_force( -1, "out of range message might be written\n" );			// drive range checks
+	rmr_vlog_force( 10, "out of range message should not be written\n" );
+
+	return errors > 0;
+}