GlimpseLogger is a simple logging utility designed to handle OpenGL error logging and general message logging. It supports multiple output targets and can handle fatal errors by terminating the application.
To use GlimpseLogger in your project, follow these steps:
- Clone the repository:
git clone https://github.com/MankowskiNick/glimpse.git
- Navigate to the project directory:
cd glimpse - Build the project using
cmake:mkdir build cd build cmake .. make
Here's a brief overview of how to use GlimpseLogger:
-
Create new logger
Glimpse::GlimpseLogger logger(); -
Add a new logging output:
GLOut* newOutput = new ConsoleOutput(); logger.AddLogging(newOutput); // Alternatively, you can pass a GLOut to the Glimpse::GlimpseLogger constructor. Glimpse::GlimpseLogger newLogger(newOutput);
-
Log a message:
logger.Log("This is a warning.", Glimpse::WARNING); logger.Log("This is a fatal error." Glimpse::FATAL);
-
Log an OpenGL error:
int errorCode = glGetError(); logger.LogGL(errorCode);
Building New Outputs Using the GLOut Abstract Class
To create a new output type for the GlimpseLogger, you need to derive a class from the GLOut abstract class and implement the Output method. This method will define how the log messages are handled and where they are sent.
- Include Necessary Headers: Ensure you include the glout.h header file and any other necessary headers.
- Derive from GLOut: Create a new class that inherits from GLOut.
- Implement the Output Method: Define the behavior of the Output method to handle log messages.
Here is an example of how to create a console output class that prints log messages to the standard output.
Creating output class
Start by creating an output class that inherits from GLOut and implements the Output method.
#include "glout.h"
#include <iostream>
namespace Glimpse {
class ConsoleOutput : public GLOut {
public:
// Destructor
virtual ~ConsoleOutput() {}
// Implement the Output method
void Output(const std::string& message, const GLLogStatus status) override {
std::cout << "Status: " << status << " - Message: " << message << std::endl;
}
};
}Adding the New Output to GlimpseLogger
Once you have created your new output class, you need to add it to the GlimpseLogger so that it can be used for logging.
#include "glimpse.h"
#include "consoleoutput.h"
int main(); Glimpse::GlimpseLogger logger();
// Create an instance of the new output class
Glimpse::ConsoleOutput* consoleOutput = new Glimpse::ConsoleOutput();
// Add logging
g
logger.AddLogging(consoleOutput);
// Log a message
logger.Log("This is a test message", INFO);
return 0;
}We welcome contributions to GlimpseLogger! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Open a pull request.