summaryrefslogtreecommitdiff
path: root/java/broker/src/velocity/templates/org/apache/qpid/server/logging
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-07-24 11:32:40 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-07-24 11:32:40 +0000
commit4216f29cf38e35f4ab764c11a8374bc55a8ae2cf (patch)
tree6ad7dbff44550b9428f7bd7a0fc34b251c8eb157 /java/broker/src/velocity/templates/org/apache/qpid/server/logging
parent6bed8ffff53f1006eee53bf25a90329f9096bdea (diff)
downloadqpid-python-4216f29cf38e35f4ab764c11a8374bc55a8ae2cf.tar.gz
QPID-2001 : Update to provide control of options in messages.
Update to improve formatting of generated code Inclusion of more documentation Defaulted generation to use US locale Removed duplicate messages in MST that were added to while the option solution was being discussed. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@797421 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker/src/velocity/templates/org/apache/qpid/server/logging')
-rw-r--r--java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm95
1 files changed, 89 insertions, 6 deletions
diff --git a/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm b/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
index 6656763ab9..917901a18b 100644
--- a/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
+++ b/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
@@ -33,7 +33,10 @@ import java.util.ResourceBundle;
* This file is based on the content of LogMessages.properties
*
* It is generated so that we can provide compile time validation of the
- * message parameters
+ * message parameters.
+ *
+ * DO NOT EDIT DIRECTLY THIS FILE IS GENERATED.
+ *
*/
public class ${type.name}Messages
{
@@ -51,25 +54,105 @@ public class ${type.name}Messages
_formatter.setLocale(currentLocale);
}
+##
+## The list stored under key 'list' in the 'type' HashMap contains all the
+## log messages that this class should contain. So for each entry in the list
+## this template will create a new log method.
+##
#foreach( $message in ${type.list} )
/**
* Log a ${type.name} message of the Format:
- * <pre>${message.format}</pre>
+ * <pre>${message.format}</pre>
+ * Optional values are contained in [square brackets] and are numbered
+ * sequentially in the method call.
+ *
*/
+## There is a lot in the method header here. To make it more readable/understandable
+## This is the same text laid out to be easier to read:
+## public static LogMessage ${message.methodName} (
+## #foreach($parameter in ${message.parameters})
+## ${parameter.type} ${parameter.name}
+## #if (${velocityCount} != ${message.parameters.size()} )
+## ,
+## #end
+## #end
+## #if(${message.parameters.size()} > 0 && ${message.options.size()} > 0)
+## ,
+## #end
+## #foreach($option in ${message.options})
+## boolean ${option.name}
+## #if (${velocityCount} != ${message.options.size()} )
+## ,
+## #end
+## #end
+## )
+##
+## What is going on is that we set the method name based on the HashMap lookup
+## for 'methodName' Then for each entry(another HashMap) in the list stored
+## in the HashMap under 'parameters' build the argument list of from the 'type'
+## and 'name' values. Ensuring that we add a ', ' between each entry.
+##
+## However, check that we are not at the last entry of the list as we don't
+## want to add ', ' at then end.
+##
+## Before we go on to the options we perform a check to see if we had any
+## parameters. If we did and we have options to add then we add ', ' to keep
+## the syntax correct.
+##
+## We then go on to the options that are again retrieved from the top HashMap
+## with key 'options'. For each option a boolean argument is created and the
+## name is retrieved from the option HashMap with key 'name'
+##
public static LogMessage ${message.methodName}(#foreach($parameter in ${message.parameters})${parameter.type} ${parameter.name}#if (${velocityCount} != ${message.parameters.size()} ), #end
-#end)
+#end#if(${message.parameters.size()} > 0 && ${message.options.size()} > 0), #end#foreach($option in ${message.options})boolean ${option.name}#if (${velocityCount} != ${message.options.size()} ), #end#end)
{
final Object[] messageArguments = {#foreach($parameter in ${message.parameters})${parameter.name}#if (${velocityCount} != ${message.parameters.size()} ), #end#end};
-
_formatter.applyPattern(_messages.getString("${message.name}"));
+
+ ## If we have some options then we need to build the message based
+ ## on those values so only provide that logic if we need it.
+#if(${message.options.size()} > 0)
+ String rawMessage = _formatter.format(messageArguments);
+
+ StringBuffer msg =new StringBuffer("${message.name} : ");
+
+ // Split the formatted message up on the option values so we can
+ // rebuild the message based on the configured options.
+ String[] parts = rawMessage.split("\\[");
+ msg.append(parts[0]);
+
+ int end;
+ if (parts.length > 1)
+ {
+ ## For Each Optional value check if it has been enabled and then
+ ## append it to the log.
+#foreach($option in ${message.options})
+
+ // Add Option : ${option.value}
+ end = parts[${velocityCount}].indexOf(']');
+ if (${option.name})
+ {
+ msg.append(parts[${velocityCount}].substring(0, end));
+ }
+
+ // Use 'end + 1' to remove the ']' from the output
+ msg.append(parts[${velocityCount}].substring(end + 1));
+#end
+ }
+
+ final String message = msg.toString();
+#else
+ ## If we have no options then we can just format and set the log
+ final String message = "${message.name} : " + _formatter.format(messageArguments);
+#end
+
return new LogMessage()
{
public String toString()
{
- return "${message.name} : " + _formatter.format(messageArguments);
+ return message;
}
};
-
}
#end