Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly Callable Functionality for Logging of App Activity Within CoreSDK #122

Closed
wants to merge 19 commits into from

Conversation

njsch
Copy link
Contributor

@njsch njsch commented Sep 5, 2020

closes #115.

This enhancement takes advantage of the already-included external Easylogging++ code and allows it to be explicitly called by third-party apps using Splashkit, not just inside the SDK's internal code itself.

Intending to work on this with @hugglesfox. Currently it is in draft mode and untested, just putting this PR here for reference and to automatically close the issue I created when done.

At the moment, it is mildly configurable but it is impossible to set logging levels. I don't really understand how to do this when a hierarchical model is not used by default in Easylogging++.

Also still learning the ropes when it comes to headerdoc (which I believe also cannot be installed on Windows) so unsure as to where to put docstrings/documentation comments.

…ore SDK and third-party apps via easylogging++. Contains base config and initialisation options but currently no way of setting levels (hierarchical model is not default for Easyloggingpp).
@njsch
Copy link
Contributor Author

njsch commented Sep 8, 2020

@macite and @hugglesfox, we have a problem, potentially caused by backend logging support: now that I have exposed logging to the core SDK, it implicitly assumes that logging is supposed to be on all the time, hence the necessity of not explicitly calling the INITIALISE_EASYLOGGING macro to avoid compilation errors, as warned by the Easyloggingpp readme. Now every time I run a program for SIT102, a default my_easylogging log file is always created. How can we avoid this?

@macite
Copy link
Member

macite commented Sep 11, 2020

I just had a quick look, and this approach isn't going to work. The idea inside SplashKit is to create a simplified interface for others to use. So you will need to create our own Logging interface - something that is simple and easy to use. Internally we can then use easylogging to do much of the work for us.

So think about the features that we want to offer via logging, and some sensible defaults for things like the log format. Keep the focus on simplicity over large numbers of features. Also keep the interface to using just basic type in parameters.

@njsch
Copy link
Contributor Author

njsch commented Sep 11, 2020

Okay so we keep the interfaces separate. Hopefully that will make things easier. So @macite, this means you expect implementation and deployment to be pretty much purely procedural?

@hugglesfox
Copy link
Contributor

I decided to implement logging myself using the write() function in SplashKit as I wanted a little more flexibility when it comes to how it is displayed. We might be able to use parts of that implementation here? https://github.com/hugglesfox/firestorm/blob/master/src/logging.cpp

@njsch
Copy link
Contributor Author

njsch commented Sep 13, 2020

@hugglesfox, yes, looks pretty close to what I was thinking of implementing. Do you want to contribute to the PR from your own account for credit purposes, or should I just add the code in with appropriate adjustments, if / where necessary?

@hugglesfox
Copy link
Contributor

@njsch I don’t mind. What ever is easiest. As long as the feature is implemented that’s the main thing.

@njsch njsch changed the title Explicitly Callable Functionality for Logging of App Activity Via Easylogging++ Explicitly Callable Functionality for Logging of App Activity Within CoreSDK Sep 14, 2020
@njsch
Copy link
Contributor Author

njsch commented Sep 14, 2020

@macite, I'm having trouble compiling Hayley's code. I don't think it is possible to hash-include splashkit.h, so I included terminal.h for write() and write_line() but the compiler can't find them, even after explicitly using the splashkit_lib namespace. Output is below:

/C/GitInit/njsch/splashkit-core/projects/cmake
[ 41%] Building CXX object CMakeFiles/SplashKitBackend.dir/C/GitInit/njsch/splas
hkit-core/coresdk/src/coresdk/keyboard_input.cpp.obj                            
[ 42%] Building CXX object CMakeFiles/SplashKitBackend.dir/C/GitInit/njsch/splashkit-core/coresdk/src/coresdk/line_drawing.cpp.obj         
                    
[ 43%] Building CXX object CMakeFiles/SplashKitBackend.dir/C/GitInit/njsch/splas
hkit-core/coresdk/src/coresdk/line_geometry.cpp.obj                             
[ 44%] Building CXX object CMakeFiles/SplashKitBackend.dir/C/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp.obj              
                    
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp: In function 'vo
id log(LogLevel, std::__cxx11::string)':                                        
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp:18:5: error: 'write' was not declared in this scope                        
                    
     write("DEBUG: ");                                                          
     ^~~~~                                                                    
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp:18:5:
note: sugg
ested alternative:                                                              
In file included from C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/loggin
g.h:4,                                                                          from C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/loggin
g.cpp:1:                                                                        
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/terminal.h:129:10: note:   'splashkit_lib::write'                                       
                   
     void write(char data);                                                     
          ^~~~~ 
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp:35:3: error: 'wr
ite' was not declared in this scope                                             write(str_time.substr(0, str_time.length() - 1));       
                    
   ^~~~~                                                                        
C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp:35:3: note: sugg
ested alternative:                                                              In file included from C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/loggin
g.h:4,                                                                          
                 from C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/loggin
g.cpp:1:                                                                        C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/terminal.h:129:10:
note:   '
splashkit_lib::write'                                                           
     void write(char data);                                                     
          ^~~~~                                                                 make[2]: *** [CMakeFiles/SplashKitBackend.dir/build.make:648:
CMakeFiles/SplashK
itBackend.dir/C/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.cpp.obj
] Error 1                                                                       make[1]: *** [CMakeFiles/Makefile2:147: CMakeFiles/SplashKitBackend.dir/all]
Err
or 2                                                                            
make: *** [Makefile:130: all] Error 2                                           
                    
Nathaniel@NJSchmidtLapTop MINGW64 /C/GitInit/njsch/splashkit-core/projects/cmake
$ 

@macite macite changed the base branch from develop to master September 15, 2020 00:19
@macite macite changed the base branch from master to develop September 15, 2020 00:19
@macite
Copy link
Member

macite commented Sep 15, 2020

I've fixed up a few things for you:

  • Missing namespace (hence no access to write - it would also mean it wasn't accessible to splashkit)
  • Naming and indentation adjusted to use coding convention from project
  • Added missing prototype to the test header
  • Removed the log level from the header (you will need to create functions/procedures to read and update this)

Looking good at the moment. Keep working on it.

@macite
Copy link
Member

macite commented Sep 15, 2020

I've pushed changes to your branch, so you will need to pull these into your local repo.

@njsch
Copy link
Contributor Author

njsch commented Sep 15, 2020

@macite,
RE comment 1: I thought I already added the Splashkit_lib namespace in particular, but thanks for the additions.
RE comment 2: I updated the njsch/develop branch a few days ago but not njs/logging. Could this potentially create merge conflict issues if I end up doing a two-fold fetch-merge command on my develop branch?

Thanks.

@macite
Copy link
Member

macite commented Sep 15, 2020

You should be able to keep working on this in your logging branch. Best to isolate this change and finish it off before incorporating other changes.

njsch added 2 commits October 19, 2020 14:14
… to add to log files but due to syntax errors with utility_functions, one cannot compile and test the code.
@njsch
Copy link
Contributor Author

njsch commented Oct 20, 2020

@macite and @hugglesfox, added my latest changes for draft analysis but haven't been able to test due to a syntax error with utility_functions. I have attempted to add support for an output log file with a configurable status between console mode, file only mode or both a file and console output mode.

@njsch
Copy link
Contributor Author

njsch commented Nov 7, 2020

@macite, @hugglesfox: Any suggestions for (a) appropriate memory clean up when closing a log output file; and (b) how I can stop the compiler from assuming that the third parameter of set_log_status(), passed by reference, should have a default argument value?

@hugglesfox
Copy link
Contributor

a) Putting log_file.close() after you finish writing to it should do the trick. I would consider moving the log_file.open() into the log() function so then your opening and closing the file within the same function as it’ll make things a little easier.

b)

In a function declaration, after a parameter with a default argument, all subsequent parameters must
have a default argument supplied in this or a previous declaration from the same scope

https://en.cppreference.com/w/cpp/language/default_arguments

But I couldn’t see a function override in that same scope? So not sure where it’s getting the default value from but reordering the arguments so that all the default arguments are last should fix it.

Copy link
Member

@macite macite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good. I've added some inline comments that will hopefully help progress this further.

Please check the naming convention of commit messages. You want them to be like FIX: Added close_log used to close log files, or NEW: Added additional log options, or QUALITY: Fixed up indentation issues in logging code etc.

FIX is for commits that fix some form of issue. NEW is for new functionality. QUALITY is for things that tidy up implementations without adding or fixing things.

Hope that helps.

coresdk/src/coresdk/logging.cpp Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.cpp Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.cpp Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.cpp Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.cpp Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.h Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.h Outdated Show resolved Hide resolved
coresdk/src/coresdk/logging.h Outdated Show resolved Hide resolved
coresdk/src/test/test_logging.cpp Outdated Show resolved Hide resolved
coresdk/src/test/test_logging.cpp Outdated Show resolved Hide resolved
@njsch
Copy link
Contributor Author

njsch commented Nov 17, 2020

@macite, why exactly are we using sk_init_logging in the backend, as the external logging module is separate from the easylogging implementation?

@macite
Copy link
Member

macite commented Nov 17, 2020

@njsch given we need to initialise this logging module I think it fits - no need to have two separate initialisation processes. This would then be setup on the first use of anything that does require initialisation - which would include the logging functions. You would need to make sure to call the base init function in the logging methods that need this initialisation to have occurred.

@njsch
Copy link
Contributor Author

njsch commented Nov 21, 2020

Partially implemented @macite's requested changes but still unsure of a few things:

  1. Fixed: Break after return
  2. Query: I'm stuck with how to do memory cleanup within the backend logging driver's initialisation process if I create a close_logger procedure, as I can't use bool quit_requested, since it seems that event processing only works seemlessly in conjunction with graphics. How can I replicate this in a non-GUI project? All it needs to know is simply when to close the open log file upon app closure and / or destruction of other Splashkit-associated types / objects.
  3. Query RE switch (level): I'm still not quite sure how to do this without being too repetetive.
  4. Todo: Neglected to simplify processing of messages to output options via local string variable..
  5. Added a NONE option to both log_level and log_mode.
  6. Explicitly overloaded the now renamed init_custom_logger without duplicating implementation.
  7. Still reluctant to add extra procedures for debug_log etc, as it would be safe to assume that anyone wanting to use a logging extension will probably already possess enough knowledge to be wanting to use this on the side to track more advanced features. If the student programmer (even first-year CompSci / CybSec / InfoTech / AI) wants to use logging but cannot do much beyond very basic procedure calls then they should probably go back and review their notes before proceeding.
  8. Test log file now appears in the current directory.
  9. Indentation should be fixed by convention.

@njsch
Copy link
Contributor Author

njsch commented Dec 2, 2020

@macite, There is an error with my attempt at overloading. Why won't it accept the two as opposed to three possible argument scenarios? Errors below:

 [ 80%] Building CXX object CMakeFiles/sktest.dir/C/GitInit/njsch/splashkit-core/coresdk/src/test/test_logging.cpp.obj                                                                                                                                                          
 C:/GitInit/njsch/splashkit-core/coresdk/src/test/test_logging.cpp: In function 'void run_logging_test()':                                                                                                                                                                      
 C:/GitInit/njsch/splashkit-core/coresdk/src/test/test_logging.cpp:10:49: error: no matching function for call to 'init_custom_logger(const char [13], splashkit_lib::log_mode&)'                                                                                               
    10 |    init_custom_logger ("test_logging", _log_mode);                                                                                                                                                                                                                     
       |                                                 ^                                                                                                                                                                                                                      
 In file included from C:/GitInit/njsch/splashkit-core/coresdk/src/test/test_logging.cpp:1:                                                                                                                                                                                     
 C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.h:51:14: note: candidate: 'void splashkit_lib::init_custom_logger(std::string, bool, splashkit_lib::log_mode&)'                                                                                                    
    51 |         void init_custom_logger (string app_name, bool override_prev_log, log_mode &mode);                                                                                                                                                                             
       |              ^~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                        
 C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.h:51:14: note:   candidate expects 3 arguments, 2 provided                                                                                                                                                         
 C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.h:59:14: note: candidate: 'void splashkit_lib::init_custom_logger(splashkit_lib::log_mode&)'                                                                                                                       
    59 |         void init_custom_logger (log_mode &mode);                                                                                                                                                                                                                      
       |              ^~~~~~~~~~~~~~~~~~                                                                                                                                                                                                                                        
 C:/GitInit/njsch/splashkit-core/coresdk/src/coresdk/logging.h:59:14: note:   candidate expects 1 argument, 2 provided                                                                                                                                                          
 make[2]: *** [CMakeFiles/sktest.dir/build.make:200: CMakeFiles/sktest.dir/C/GitInit/njsch/splashkit-core/coresdk/src/test/test_logging.cpp.obj] Error 1                                                                                                                        
 make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/sktest.dir/all] Error 2                                                                                                                                                                                                     
 make: *** [Makefile:150: all] Error 2                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                
 Nathaniel@NJSchmidtLapTop MINGW64 /C/GitInit/njsch/splashkit-core/projects/cmake                                                                                                                                                                                               
 $                                                                                                                                                                                                                                          

@macite
Copy link
Member

macite commented Dec 2, 2020

@njsch looks like you have 2 overloads - one with one parameter and one with three parameters. There isn't one with two parameters.

Also, remember you will need to implement all of the different versions of this. In the C++ code you have the most explicit version (the one with three parameters) but not the other. Each of the others will be a single line calling the version with three parameters, and providing default options for the values it did not receive. e.g.

void init_custom_logger (string app_name, log_mode mode)
{
    init_custom_logger(app_name, true, mode);
}

I see you are passing the log_mode by reference. There is no need to do this. The code isn't updating the value passed to it, and it is already small in size as an enum (it will be the size of an integer). Removing the & will make this faster and simpler when it is mapped to other languages.

Hope that helps.

…n <log_mode> enum to <FILE_ONLY> to avoid typedef conflict with standard lib reference to <FILE>. Fixed the logging test.
@njsch
Copy link
Contributor Author

njsch commented Dec 8, 2020

FYI @macite, immediately previous commit contributes the following:

  • FIX: Overloaded init_custom_logger () properly.
  • FIX: Changed FILE in log_mode enum to FILE_ONLY to avoid typedef conflict with standard lib reference to FILE.
  • FIX: Improved The SKTest for logging; however, only the console tests work. Either the log file is not being created, or it is being saved in an unknown location - I suspect the former but do not know why.

@njsch
Copy link
Contributor Author

njsch commented Dec 15, 2020

@macite, @hugglesfox, correction from last comment: log file is being written to in ```splashkit-core/bin. But I'm not sure if the variable for setting the log level is necessarily doing its job.

@njsch njsch marked this pull request as ready for review December 15, 2020 07:44
@njsch
Copy link
Contributor Author

njsch commented Dec 15, 2020

This is not working on Mac. I can't test / fix this reliably unless I get a Mac OS VM.

@njsch
Copy link
Contributor Author

njsch commented Sep 10, 2021

Closing this for now as development seems halted on this project.

FYI @macite.

@njsch njsch closed this Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create easylogging++ wrap-around for explicit use in Splashkit core SDK
3 participants