| 72 | } |
| 73 | |
| 74 | void LogConfigHandler::configure(const Param & param) |
| 75 | { |
| 76 | StringList configurations = ListUtils::toStringList<std::string>(param.getValue(LogConfigHandler::PARAM_NAME)); |
| 77 | |
| 78 | for (StringList::const_iterator iter = configurations.begin(); iter != configurations.end(); ++iter) |
| 79 | { |
| 80 | // split by " " to get the commands |
| 81 | StringList commands; |
| 82 | iter->split(' ', commands, true); |
| 83 | |
| 84 | Logger::LogStream & log = getLogStreamByName_(commands[0]); |
| 85 | |
| 86 | // convenience variables |
| 87 | String & command = commands[1]; |
| 88 | |
| 89 | // identify action |
| 90 | if (command == "add") |
| 91 | { |
| 92 | // convenience variables |
| 93 | const String & stream_name = commands[2]; |
| 94 | |
| 95 | // add the stream given by the 3rd argument to the defined log |
| 96 | if (stream_name == "cout") |
| 97 | { |
| 98 | log.insert(cout); |
| 99 | } |
| 100 | else if (stream_name == "cerr") |
| 101 | { |
| 102 | log.insert(cerr); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | if (commands.size() <= 3) // write error to cerr and not a LogStream (because we're just configuring it...) |
| 107 | { |
| 108 | std::cerr << "Error during configuring logging: the command '" << (*iter) << "' requires 4 entries but has only " << commands.size() << "\n"; |
| 109 | continue; |
| 110 | } |
| 111 | const String & stream_type = commands[3]; |
| 112 | |
| 113 | // check if a stream with the same name, but different type was already registered |
| 114 | if (stream_type_map_.count(stream_name) != 0) |
| 115 | { |
| 116 | if (stream_type_map_[stream_name] != getStreamTypeByName_(stream_type)) |
| 117 | { |
| 118 | throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "A stream with the same name but different type was already registered."); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | StreamHandler::StreamType type = getStreamTypeByName_(stream_type); |
| 123 | Int status = STREAM_HANDLER.registerStream(type, stream_name); |
| 124 | |
| 125 | if (!status) |
| 126 | { |
| 127 | // operation failed |
| 128 | throw Exception::FileNotWritable(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, commands[2]); |
| 129 | } |
| 130 | |
| 131 | log.insert(STREAM_HANDLER.getStream(type, stream_name)); |
no test coverage detected