You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Add the ability to plug a logger into SOQL Lib.
Solution A
What a developer/client needs to do to use the logger:
Create an Apex class called SOQLLogger.
The class should implement the SOQL.Logger interface.
globalclassSOQLLoggerimplementsSOQL.Logger {
publicvoidlog(SOQL.Errorerror) {
// Use your own logger here
}
}
Pros
SOQL Lib has no dependency, not even a loose one, on other libraries such as Nebula.
SOQL.Error contains all the details about the failed query, such as the exception, query string, access level, etc. and the structure is static.
Easy to implement: just create a class called SOQLLogger that implements SOQL.Logger.
This is a form of adapter and can be used with any kind of logger. The developer can take whatever information they need from SOQL.Error, transform it, and log it using their own logger.
We can have more evens in the future e.g. Exception when SOQL in a loop #243 - sending "warn" event when the same query was executed a few times.
Cons
The developer has to follow the naming convention: SOQLLogger.
There is an extra step for projects that already use both SOQL Lib and Nebula, because the class still needs to be created and maintained.
Solution B
What a developer/client needs to do to use the logger:
Has Nebula?
Nothing. SOQL Lib will use the Nebula logger when it is found.
Doesn't have Nebula?
Create an SOQLLogger class, but based on System.Callable.
If the Nebula logger is available in the project, no action is needed. SOQL Lib errors will be logged automatically.
Cons
If the Nebula logger is available in the project, errors will be logged automatically, with no way to control that behavior.
For projects without Nebula, this is much more complicated and less clean, because developers have to use Map<String, Object> in the same format used by Nebula.
Not all query details will be available. For example, queryString, accessLevel, etc. will be missing.
tags, saveLog, message, and loggingLevel will be hardcoded in SOQL Lib and will have constant values, so developers cannot change them without modifying SOQL Lib.
Technical Details
Solution A
In SOQL Lib:
publicinterfaceLogger {
voidlog(SOQL.Errorerror);
}
publicclassError {
publicExceptionexception;
Stringquery;
AccessLevelaccessLevel;
// Other information about the failed query
}
privatestaticLoggerlogger {
get {
if (logger == null) {
Typetype = Type.forName('SOQLLogger');
logger = type != null ? (Logger) type.newInstance() : newDefaultLogger(); // ??
}
returnlogger;
}
}
// toList(), toObject(), etc.try {
// Execute query
} catch (Exceptione) {
Errorerror = ...;
this.logger.log(error);
}
Solution B
In SOQL Lib:
privatestaticSystem.Callablelogger {
get {
if (logger == null) {
// Nebula by defaultTypeloggerType = System.Type.forName('Nebula', 'CallableLogger');
if (loggerType == null) {
loggerType = System.Type.forName(null, 'CallableLogger');
}
if (loggerType == null) {
loggerType = System.Type.forName('SOQLLogger');
}
logger = loggerType == null ? null : (System.Callable) loggerType.newInstance();
}
returnlogger;
}
}
Feature Request: Add Logger Support to SOQL Lib
Is your feature request related to a problem? Please describe.
Add the ability to plug a logger into SOQL Lib.
Solution A
What a developer/client needs to do to use the logger:
SOQLLogger.SOQL.Loggerinterface.Pros
SOQL.Errorcontains all the details about the failed query, such as the exception, query string, access level, etc. and the structure is static.SOQLLoggerthat implementsSOQL.Logger.SOQL.Error, transform it, and log it using their own logger.Cons
SOQLLogger.Solution B
What a developer/client needs to do to use the logger:
Has Nebula?
Nothing. SOQL Lib will use the Nebula logger when it is found.
Doesn't have Nebula?
Create an
SOQLLoggerclass, but based onSystem.Callable.Pros
Cons
Map<String, Object>in the same format used by Nebula.queryString,accessLevel, etc. will be missing.tags,saveLog,message, andloggingLevelwill be hardcoded in SOQL Lib and will have constant values, so developers cannot change them without modifying SOQL Lib.Technical Details
Solution A
In SOQL Lib:
Solution B
In SOQL Lib: