Skip to content
Snippets Groups Projects
Commit 89890dca authored by brinn's avatar brinn
Browse files

change: make the determination of the log level more flexible by using the LogAnnotation.logLevel()

SVN: 4331
parent 5be2fd27
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ public final class LogInvocationHandler implements InvocationHandler ...@@ -33,7 +33,7 @@ public final class LogInvocationHandler implements InvocationHandler
{ {
private final Object object; private final Object object;
private final String name; private final String name;
private final Level logLevel; private final Level defaultLogLevel;
private final Class<?> classUsedToNameLogger; private final Class<?> classUsedToNameLogger;
/** /**
...@@ -48,7 +48,7 @@ public final class LogInvocationHandler implements InvocationHandler ...@@ -48,7 +48,7 @@ public final class LogInvocationHandler implements InvocationHandler
{ {
this.object = object; this.object = object;
this.name = name; this.name = name;
this.logLevel = logLevel; this.defaultLogLevel = logLevel;
this.classUsedToNameLogger = classUsedToNameLogger; this.classUsedToNameLogger = classUsedToNameLogger;
} }
...@@ -73,6 +73,7 @@ public final class LogInvocationHandler implements InvocationHandler ...@@ -73,6 +73,7 @@ public final class LogInvocationHandler implements InvocationHandler
throw t; throw t;
} finally } finally
{ {
final Level logLevel = getLogLevel(method);
final Logger logger = createLogger(method); final Logger logger = createLogger(method);
if (throwable != null || logger.isEnabledFor(logLevel)) if (throwable != null || logger.isEnabledFor(logLevel))
{ {
...@@ -101,8 +102,23 @@ public final class LogInvocationHandler implements InvocationHandler ...@@ -101,8 +102,23 @@ public final class LogInvocationHandler implements InvocationHandler
} }
} }
} }
private Logger createLogger(Method method) private Level getLogLevel(Method method)
{
final LogAnnotation annotation = method.getAnnotation(LogAnnotation.class);
if (annotation == null)
{
return Level.DEBUG;
} else if (annotation.logLevel().equals(LogLevel.UNDEFINED))
{
return defaultLogLevel;
} else
{
return Log4jSimpleLogger.toLog4jPriority(annotation.logLevel());
}
}
private Logger createLogger(Method method)
{ {
final LogAnnotation annotation = method.getAnnotation(LogAnnotation.class); final LogAnnotation annotation = method.getAnnotation(LogAnnotation.class);
final LogCategory logCategory = (annotation == null) ? LogCategory.ACCESS : annotation.logCategory(); final LogCategory logCategory = (annotation == null) ? LogCategory.ACCESS : annotation.logCategory();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment