Clean up cruft and basic file logging setup #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For logging we can use lombok's automation and Slf4j (I think slf4j is better than apache CommonsLog, both can act as bridges for logging implementations but slf4j seems to be more "robust" in their own words)
It'll look something like this:
Springboot uses logback by default which will connect to the Slf4j abstraction. The advantage is if we want to migrate to log4j2 (which is supposed to be the successor to logback and is more complicated) it should be drag and drop.
We also should figure out how to properly use exceptions; it does not make sense to raise a RuntimeException when a function fails, such as a user that does not exist. For one, RuntimeException is too broad. For another, we would have to catch this exception for every thing that calls it. I think this is fine if the exception isn't too broad (what if a RuntimeException happens in the internal code?). Alternatively, the function can simply return an invalid value of some sort and log some handwritten error. Also, raising a RuntimeException and forgetting to catch it will result in the entire backend (or server) crashing, which will require a restart.
Currently I'm not too sure how we should "implement" logging; we seem to rely heavily on these exceptions crashing the app and dumping the traceback once the app (or rather thread) is killed. Adding log statements around wouldn't be too hard, but can quickly litter the log (though it's probably fine). Also logback uses rotation logging with a max file size. Ideally, I want to hold an entire days log, and deal with the filesize constraints later. Then dump/copy the log into some form of long(er) term storage.
This PR also renames our package structure. I'm not sure why we were doing
com.example.package
, which is likely taken from the springboot boilerplate code, instead of just doingcom.package
, sincecom.example
wouldn't actually point to anything.Heads up, if we don't want to use Lombok for annotation, it's also fine, but we should determine early on (technically, lombok is a hack around java, so some developers may be opposed to it. It may also cause incompatibility issues with certain IDEs). It wouldn't be too big of a deal (right now), as we can manually put in the below or define our own annotation: