Elaztek Developer Hub
Blamite Game Engine - blam!  00423.10.27.24.0533.blamite
The core library for the Blamite Game Engine.
log.hpp
Go to the documentation of this file.
1 #include "../console.h"
2 
4 
6 {
14  {
15  public:
17  {
18  name = "log";
19  description = "Logs an error to the console.";
20  syntax = "log [WARNING|ERROR|SEVERE] [FORCE] <message>";
21 
23  }
24 
25  BlamResult Execute(std::vector<std::string> arguments)
26  {
27  if (arguments.size() == 0)
28  {
29  return BlamResult::Error_Command_WrongArgumentCount;
30  }
31 
32  int skip_args = 0;
33 
34  BlamLogLevel log_level = BlamLogLevel::None;
35  {
36  bool valid_log_level = false;
37 
38  if (arguments.size() >= 1)
39  {
40  std::string log_level_string = str_tolower(arguments[0]);
41 
42  if (log_level_string == "info")
43  {
44  log_level = BlamLogLevel::None;
45  valid_log_level = true;
46  }
47  else if (log_level_string == "warning")
48  {
49  log_level = BlamLogLevel::Warning;
50  valid_log_level = true;
51  }
52  else if (log_level_string == "error")
53  {
54  log_level = BlamLogLevel::Error;
55  valid_log_level = true;
56  }
57  else if (log_level_string == "severe")
58  {
59  log_level = BlamLogLevel::Severe;
60  valid_log_level = true;
61  }
62  }
63 
64  if (valid_log_level)
65  {
66  skip_args = 1;
67  }
68  }
69 
70  bool force = false;
71 
72  if (arguments.size() >= skip_args + 1)
73  {
74  if (str_tolower(arguments[skip_args]) == "force")
75  {
76  force = true;
77  skip_args++;
78  }
79  }
80 
81  std::string message_text = "";
82 
83  for (int i = skip_args; i < arguments.size(); i++)
84  {
85  if (i == arguments.size() - 1)
86  {
87  message_text += arguments[i];
88  }
89  else
90  {
91  message_text += arguments[i] + " ";
92  }
93  }
94 
95  if (force)
96  {
97  Blam::Logger::LogEventForce(message_text, log_level);
98  }
99  else
100  {
101  Blam::Logger::LogEvent(message_text, log_level);
102  }
103 
104  return BlamResult::Success_OK;
105  }
106  };
107 }
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:130
BlamConsoleCommand::description
std::string description
An optional description of the command. Shown when using the classify command.
Definition: console.h:36
logger.h
BlamConsoleCommand
Class used to represent a console command.
Definition: console.h:33
Blam::Resources::Console::LogCommand::Execute
BlamResult Execute(std::vector< std::string > arguments)
Called upon command execution.
Definition: log.hpp:25
Blam::Resources::Console::LogCommand
Class for the log command.
Definition: log.hpp:13
BlamConsoleCommand::name
std::string name
The name of the console command.
Definition: console.h:35
BlamConsoleCommand::syntax
std::string syntax
The syntax information for the command. Shown to the user when using the help command with an argumen...
Definition: console.h:37
BlamConsoleCommand::type
BlamCommandType type
The type of command this is. See #Blam::Resources::Console::BlamCommandType for more information.
Definition: console.h:40
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:262
Blam::Resources::Console::LogCommand::LogCommand
LogCommand()
Definition: log.hpp:16
Blam::Resources::Console
Namespace for things relating to the debug console.
Definition: abort.hpp:5
BlamCommandType::Builtin
@ Builtin
A command that is hard-coded into the engine.