OpcUaCanOpen
CANopen OPC-UA server
LogLevels.cpp
Go to the documentation of this file.
1 /* © Copyright CERN, 2015. All rights not expressly granted are reserved.
2  * LogLevels.cpp
3  *
4  * Created on: Aug 18, 2015
5  * Author: Benjamin Farnham <benjamin.farnham@cern.ch>
6  *
7  * This file is part of Quasar.
8  *
9  * Quasar is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public Licence as published by
11  * the Free Software Foundation, either version 3 of the Licence.
12  *
13  * Quasar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public Licence for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with Quasar. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "LogLevels.h"
23 #include <LogIt.h>
24 #include <algorithm>
25 #include <cctype>
26 
28 {
29  switch(level)
30  {
31  case(TRC): return "TRC";
32  case(DBG): return "DBG";
33  case(INF): return "INF";
34  case(WRN): return "WRN";
35  case(ERR): return "ERR";
36  default : return "UNKNOWN";
37  }
38 }
39 
41 {
42  std::string levelString(s);
43  std::transform(levelString.begin(), levelString.end(), levelString.begin(),
44  [](unsigned char c){ return std::toupper(c); } );
45 
46  if (levelString=="ERR" || levelString=="ERROR" ) out=Log::ERR;
47  else if (levelString=="WRN" || levelString=="WARN" || levelString=="WARNING" ) out=Log::WRN;
48  else if (levelString=="INF" || levelString=="INFO" || levelString=="INFORMATION") out = Log::INF;
49  else if (levelString=="DBG" || levelString=="DEBUG") out = Log::DBG;
50  else if (levelString=="TRC" || levelString=="TRACE") out = Log::TRC;
51  else
52  {
53  LOG(Log::WRN) << "failed to parse log level string ["<<s<<"] to log level";
54  return false;
55  }
56  return true;
57 }