use of com.axway.ats.core.log.AtsConsoleLogger in project ats-framework by Axway.
the class ActiveDbAppender method getCurrentInstance.
/**
* This method doesn't create a new instance,
* but returns the already created one (from log4j2) or null if there is no such.
*
* @return the current DB appender instance
*/
public static ActiveDbAppender getCurrentInstance() {
if (instance == null) {
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
Map<String, Appender> appenders = config.getAppenders();
// maybe we should use this one to obtain Active and Passive DB appenders?
if (appenders != null && appenders.size() > 0) {
for (Map.Entry<String, Appender> entry : appenders.entrySet()) {
Appender appender = entry.getValue();
if (appender instanceof ActiveDbAppender) {
instance = (ActiveDbAppender) appender;
isAttached = true;
return instance;
}
}
}
}
if (instance != null) {
return instance;
}
/*
* Configuration in log4j2.xml file was not found for ActiveDbAppender
* A dummy com.axway.ats.log.autodb.DbEventRequestProcessor is
* created in order to prevent NPE when invoking methods such as getRunId()
*/
new AtsConsoleLogger(ActiveDbAppender.class).warn("ATS Database appender is not specified in log4j2.xml file. " + "Methods such as ActiveDbAppender@getRunId() will not work.");
isAttached = false;
/**
* create dummy appender configuration
* This configuration will be replaced with one from log4j2.xml file
*/
DbAppenderConfiguration appenderConfig = new DbAppenderConfiguration();
appenderConfig.setHost(DUMMY_DB_HOST);
appenderConfig.setDatabase(DUMMY_DB_DATABASE);
appenderConfig.setUser(DUMMY_DB_USER);
appenderConfig.setPassword(DUMMY_DB_PASSWORD);
instance = new ActiveDbAppender(appenderConfig);
return instance;
}
use of com.axway.ats.core.log.AtsConsoleLogger in project ats-framework by Axway.
the class DbAppenderConfiguration method validate.
/**
* Verify that the configuration is valid - the method will throw runtime exception if
* the configuration is not valid
* @throws InvalidAppenderConfigurationException if the configuration is not valid
*/
public void validate() throws InvalidAppenderConfigurationException {
if (host == null) {
throw new InvalidAppenderConfigurationException("host");
}
if (port == null) {
new AtsConsoleLogger(getClass()).warn("Database port (\"port\" property) is not specified in log4j2.xml file, section for ATS ActiveDbAppender. " + "Assuming default value for Microsoft SQL Server databases (" + DbConnSQLServer.DEFAULT_PORT + ")");
this.port = DbConnSQLServer.DEFAULT_PORT + "";
}
if (database == null) {
throw new InvalidAppenderConfigurationException("database");
}
if (user == null) {
throw new InvalidAppenderConfigurationException("user");
}
if (password == null) {
throw new InvalidAppenderConfigurationException("password");
}
if (driver == null) {
this.driver = DbKeys.SQL_SERVER_DRIVER_JTDS;
}
if (chunkSize == null) {
this.chunkSize = AbstractDbAccess.DEFAULT_CHUNK_SIZE + "";
}
// despite the method name it actually is quite good in validating maxNumberLogEvents member
this.maxNumberLogEvents = getMaxNumberLogEvents() + "";
if (this.mode != "" && !this.mode.equalsIgnoreCase("batch")) {
boolean explicitEnableOfLogger = false;
if (AtsConsoleLogger.getLevel() == null) {
explicitEnableOfLogger = true;
AtsConsoleLogger.setLevel(Level.WARN);
}
new AtsConsoleLogger(getClass()).warn("Invalid value (" + this.mode + ") for ATS DB Appender paramenter 'mode'! Setting it to non-batch mode (empty string)");
this.mode = "";
if (explicitEnableOfLogger) {
AtsConsoleLogger.setLevel(null);
}
}
}
use of com.axway.ats.core.log.AtsConsoleLogger in project ats-framework by Axway.
the class DbEventRequestProcessor method constructUpdateRunEvent.
private void constructUpdateRunEvent() {
try {
if (userProvidedUpdateRunEvent != null) {
// get current run info from database
Run run = getLatestRun();
// replace the missing fields, received by the latest UpdateRunEvent with the one from the DB
String runName = (userProvidedUpdateRunEvent.getRunName() != null) ? userProvidedUpdateRunEvent.getRunName() : run.runName;
String osName = (userProvidedUpdateRunEvent.getOsName() != null) ? userProvidedUpdateRunEvent.getOsName() : run.os;
String productName = (userProvidedUpdateRunEvent.getProductName() != null) ? userProvidedUpdateRunEvent.getProductName() : run.productName;
String versionName = (userProvidedUpdateRunEvent.getVersionName() != null) ? userProvidedUpdateRunEvent.getVersionName() : run.versionName;
String buildName = (userProvidedUpdateRunEvent.getBuildName() != null) ? userProvidedUpdateRunEvent.getBuildName() : run.buildName;
String userNote = (userProvidedUpdateRunEvent.getUserNote() != null) ? userProvidedUpdateRunEvent.getUserNote() : run.userNote;
String hostName = (userProvidedUpdateRunEvent.getHostName() != null) ? userProvidedUpdateRunEvent.getHostName() : run.hostName;
// construct the new pending UpdateRunEvent
actualUpdateRunEvent = new UpdateRunEvent(userProvidedUpdateRunEvent.getLoggerFqcn(), (Logger) userProvidedUpdateRunEvent.getLogger(), runName, osName, productName, versionName, buildName, userNote, hostName);
}
} catch (SQLException e) {
/*
* Could not obtain run info from database.
* The exception will be logged to the console only, because the event processor is busy handling the UpdateRunEvent
* and will not be able to handle the log message event as well
*/
new AtsConsoleLogger(getClass()).error("Unable to update run with ID '" + eventProcessorState.getRunId() + "'", e);
}
}
Aggregations