use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class EntityManagerTLRJUnitTestSuite method testMergeDetachedObject.
public void testMergeDetachedObject() {
// Step 1 - read a department and clear the cache.
clearCache("fieldaccess");
EntityManager em = createEntityManager("fieldaccess");
Query query = em.createNamedQuery("findAllSQLDepartments");
Collection departments = query.getResultList();
Department detachedDepartment;
// and a second time with the department table empty.
if (departments.isEmpty()) {
beginTransaction(em);
detachedDepartment = new Department();
detachedDepartment.setName("Department X");
em.persist(detachedDepartment);
commitTransaction(em);
} else {
detachedDepartment = (Department) departments.iterator().next();
}
closeEntityManager(em);
clearCache("fieldaccess");
// Step 2 - create a new em, create a new employee with the
// detached department and then query the departments again.
em = createEntityManager("fieldaccess");
beginTransaction(em);
Employee emp = new Employee();
emp.setFirstName("Crazy");
emp.setLastName("Kid");
emp.setId(41);
emp.setDepartment(detachedDepartment);
em.persist(emp);
// the try/catch should be removed when the bug is fixed
try {
commitTransaction(em);
em.createNamedQuery("findAllSQLDepartments").getResultList();
} catch (RuntimeException e) {
getServerSession("fieldaccess").log(new SessionLogEntry(getServerSession("fieldaccess"), SessionLog.WARNING, SessionLog.TRANSACTION, e));
}
closeEntityManager(em);
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class AbstractSession method logThrowable.
/**
* PUBLIC:
* <p>
* Log a throwable with level and category.
* </p>
*
* @param level the log request level value
* @param category the string representation of a EclipseLink category.
* @param throwable a Throwable
*/
public void logThrowable(int level, String category, Throwable throwable) {
if (this.isLoggingOff) {
return;
}
// Must not create the log if not logging as is a performance issue.
if (shouldLog(level, category)) {
startOperationProfile(SessionProfiler.Logging);
log(new SessionLogEntry(this, level, category, throwable));
endOperationProfile(SessionProfiler.Logging);
}
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method createLogEntry.
/**
* Create a new instance of {@link SessionLogEntry} class and set provided session, log level, logging category
* and {@link String} message to it.
* @param level Log level of the new log entry.
* @param category Logging category of the new log entry.
* @param message {@link String} message of the new log entry.
* @return The new instance of {@link SessionLogEntry} class with all provided values set.
*/
private SessionLogEntry createLogEntry(final LogCategory category, final LogLevel level, final String message) {
final SessionLogEntry logEntry = initLogEntry(category, level);
logEntry.setMessage(message);
return logEntry;
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method testLogExceptionStackTrace.
/**
* Test {@code SLF4JLogger.log(SessionLogEntry)} method with {@link Throwable} and stack trace logging turned on.
* Matrix of logger level x category settings with all log entry log levels is being checked.
*/
public void testLogExceptionStackTrace() {
// Verify loggers for logger level x category matrix.
for (LogCategory category : LogCategory.values()) {
final String nameSpace = category.getNameSpace();
final Logger categoryLogger = loggerContext.getLogger(nameSpace);
categoryLogger.setLevel(Level.ALL);
for (LogLevel loggerLevel : LogLevel.values()) {
// Verify messages with all log levels.
logger.setLevel(loggerLevel.getId(), category.getName());
for (LogLevel messageLevel : LogLevel.values()) {
final String message = "Log message";
final String exceptionMessage = "Exception message";
final Throwable exception = new RuntimeException(exceptionMessage);
// Log entry without log message.
final SessionLogEntry logEntry1 = createLogEntry(category, messageLevel, exception);
// Log entry with log message.
final SessionLogEntry logEntry2 = createLogEntry(category, messageLevel, message, exception);
// Logback log event additional check for exception without log message.
final Check check1 = new Check() {
@Override
public void check(final ILoggingEvent logEvent) {
final String eventMessage = logEvent.getMessage();
assertTrue("No message was passed so null or empty String must be stored as a message.", eventMessage == null || eventMessage.isEmpty());
assertEquals("Exception message must be stored in throwableProxy.", exceptionMessage, logEvent.getThrowableProxy().getMessage());
}
};
// Logback log event additional check for exception with log message.
final Check check2 = new Check() {
@Override
public void check(final ILoggingEvent logEvent) {
assertEquals("Logged message \"" + message + "\" must be stored as a message.", message, logEvent.getMessage());
assertEquals("Exception message must be stored in throwableProxy.", exceptionMessage, logEvent.getThrowableProxy().getMessage());
}
};
testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry1, check1);
testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry2, check2);
}
}
}
}
use of org.eclipse.persistence.logging.SessionLogEntry in project eclipselink by eclipse-ee4j.
the class SLF4JLoggerHelper method testLogExceptionWithoutStackTrace.
/**
* Test {@code SLF4JLogger.log(SessionLogEntry)} method with {@link Throwable} and stack trace logging turned off.
* Matrix of logger level x category settings with all log entry log levels is being checked.
*/
public void testLogExceptionWithoutStackTrace() {
// Verify loggers for logger level x category matrix.
for (LogCategory category : LogCategory.values()) {
final String nameSpace = category.getNameSpace();
final Logger categoryLogger = loggerContext.getLogger(nameSpace);
categoryLogger.setLevel(Level.ALL);
for (LogLevel loggerLevel : LogLevel.values()) {
// Verify messages with all log levels.
logger.setLevel(loggerLevel.getId(), category.getName());
for (LogLevel messageLevel : LogLevel.values()) {
final Throwable exception = new RuntimeException("Exception message");
final SessionLogEntry logEntry = createLogEntry(category, messageLevel, exception);
// Logback log event additional check.
final Check check = new Check() {
@Override
public void check(final ILoggingEvent logEvent) {
assertEquals("Logged exception message \"" + exception.getMessage() + "\" must be stored as a message.", exception.toString(), logEvent.getMessage());
assertNull("There can't be any arguments for already rendered message.", logEvent.getArgumentArray());
}
};
testLogEntry(category, loggerLevel, messageLevel, categoryLogger, logEntry, check);
}
}
}
}
Aggregations