| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on this file might be covered by the GNU General Public License. |
| 19 | */ |
| 20 | |
| 21 | #include "host/logoutput.h" |
| 22 | |
| 23 | #include <algorithm> |
| 24 | #include <map> |
| 25 | |
| 26 | #include "boost_assert_handler.h" |
| 27 | |
| 28 | using namespace std; |
| 29 | |
| 30 | //----------------------------------------------------------------------------- |
| 31 | // LogOutput |
| 32 | //----------------------------------------------------------------------------- |
| 33 | |
| 34 | static map<string, LogOutput> log_output_string_map; |
| 35 | |
| 36 | /** |
| 37 | * @brief Transform the @a log_output_string into a @c LogOutput. |
| 38 | * |
| 39 | * @param log_output_string The string to be parsed. |
| 40 | * |
| 41 | * @return The @c LogOutput corresponding to the @a log_output_string. |
| 42 | */ |
| 43 | LogOutput get_log_output_from_string( const string &log_output_string ) |
| 44 | { |
| 45 | BOOST_ASSERT( !log_output_string.empty() ); |
| 46 | |
| 47 | // convert to uppercase to allow the protocol to be case insensitive |
| 48 | string log_output_uppercase_string( log_output_string ); |
| 49 | transform( log_output_string.begin(), log_output_string.end(), |
| 50 | log_output_uppercase_string.begin(), |
| 51 | ::toupper ); //lint !e534 |
| 52 | |
| 53 | // TODO move to an init method |
| 54 | log_output_string_map[ "SYSLOG" ] = LogOutput_SYSLOG; |
| 55 | log_output_string_map[ "TERMINAL" ] = LogOutput_TERMINAL; |
| 56 | log_output_string_map[ "CONSOLE" ] = LogOutput_TERMINAL; |
| 57 | log_output_string_map[ "STDERR" ] = LogOutput_TERMINAL; |
| 58 | log_output_string_map[ "FILE" ] = LogOutput_FILE; |
| 59 | |
| 60 | LogOutput protocol = log_output_string_map[ log_output_uppercase_string ]; |
| 61 | |
| 62 | return protocol; |
| 63 | } |