Issues I've identified after reading 3 chapters of "Clean Code" (I know...)
Implementationstatic async log() accepts a LoggerConfiguration interface as its parameter. The interface has three members: message, logLevel, and debugEnabled?. It contains a switch block that forks logic based upon the provided logLevel.
Problems
P1. Functions should do one thing - this one does three.
P2. debugEnabled has to be passed on every call. This should be set at creation of a Logger instance.
P3. I should strive to make log* monadic functions. Function calls are currently convoluted.
P4. LogLevel should not need to be exported to interface with the functions. It's revealing internal implementation.
Solution
S1. Break out the current log function into logInfo, logError, and logDebug public functions [P1, P3].
S2. Re-implement Logger as a proper class that can be instantiated as a class member where it is consumed. It currently lacks a constructor and only contains static functions [P2].
S3. Establish a constructor that accepts configuration argument debugEnabled, removing this from every call to log* [P2].
S4. With [S1, S2, S3] implemented, the LogLevel enum can be abolished.
I'll have to go through the whole codebase to update function calls, and this will be much cleaner in the end.
Issues I've identified after reading 3 chapters of "Clean Code" (I know...)
Implementation
static async log()
accepts aLoggerConfiguration
interface as its parameter. The interface has three members:message
,logLevel
, anddebugEnabled?
. It contains aswitch
block that forks logic based upon the provided logLevel.Problems P1. Functions should do one thing - this one does three. P2.
debugEnabled
has to be passed on every call. This should be set at creation of a Logger instance. P3. I should strive to make log* monadic functions. Function calls are currently convoluted. P4. LogLevel should not need to be exported to interface with the functions. It's revealing internal implementation.Solution S1. Break out the current
log
function intologInfo
,logError
, andlogDebug
public functions [P1, P3]. S2. Re-implement Logger as a proper class that can be instantiated as a class member where it is consumed. It currently lacks a constructor and only contains static functions [P2]. S3. Establish a constructor that accepts configuration argumentdebugEnabled
, removing this from every call to log* [P2]. S4. With [S1, S2, S3] implemented, theLogLevel
enum can be abolished.I'll have to go through the whole codebase to update function calls, and this will be much cleaner in the end.