Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaofang li
Logging Log4j2
Commits
2e42ea8b
Commit
2e42ea8b
authored
8 years ago
by
Gary Gregory
Browse files
Options
Download
Email Patches
Plain Diff
Order the new methods in AB order and add @since 2.9 tags.
parent
ec27fe7b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
+209
-169
...ain/java/org/apache/logging/log4j/message/MapMessage.java
log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
+51
-40
...g/apache/logging/log4j/message/StructuredDataMessage.java
with
260 additions
and
209 deletions
+260
-209
log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
+
209
-
169
View file @
2e42ea8b
...
...
@@ -180,18 +180,6 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiformatMes
return
data
.
containsKey
(
key
);
}
/**
* Adds an item to the data Map in fluent style.
* @param key The name of the data item.
* @param value The value of the data item.
* @return {@code this}
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
String
value
)
{
put
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
...
...
@@ -205,163 +193,6 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiformatMes
data
.
putValue
(
key
,
value
);
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
int
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
long
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
boolean
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
char
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
byte
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
short
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
Object
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
float
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
double
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
protected
void
validate
(
final
String
key
,
final
boolean
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
char
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
byte
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
short
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
Object
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
float
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
double
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
String
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
int
value
)
{
// do nothing
}
protected
void
validate
(
final
String
key
,
final
long
value
)
{
// do nothing
}
/**
* Adds all the elements from the specified Map.
* @param map The Map to add.
...
...
@@ -626,4 +457,213 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiformatMes
public
Throwable
getThrowable
()
{
return
null
;
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
boolean
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
byte
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
char
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
double
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
float
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
int
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
long
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
Object
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
short
value
)
{
// do nothing
}
/**
* @since 2.9
*/
protected
void
validate
(
final
String
key
,
final
String
value
)
{
// do nothing
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
boolean
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
byte
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
char
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
double
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
float
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
int
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
long
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
Object
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map.
* @param key The name of the data item.
* @param value The value of the data item.
* @return this object
* @since 2.9
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
short
value
)
{
validate
(
key
,
value
);
data
.
putValue
(
key
,
value
);
return
(
M
)
this
;
}
/**
* Adds an item to the data Map in fluent style.
* @param key The name of the data item.
* @param value The value of the data item.
* @return {@code this}
*/
@SuppressWarnings
(
"unchecked"
)
public
M
with
(
final
String
key
,
final
String
value
)
{
put
(
key
,
value
);
return
(
M
)
this
;
}
}
This diff is collapsed.
Click to expand it.
log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
+
51
-
40
View file @
2e42ea8b
...
...
@@ -133,18 +133,6 @@ public class StructuredDataMessage extends MapMessage<StructuredDataMessage, Str
}
/**
* Add an item to the data Map in fluent style.
* @param key The name of the data item.
* @param value The value of the data item.
* @return {@code this}
*/
@Override
public
StructuredDataMessage
with
(
final
String
key
,
final
String
value
)
{
put
(
key
,
value
);
return
this
;
}
/**
* Returns the supported formats.
* @return An array of the supported format names.
...
...
@@ -216,25 +204,6 @@ public class StructuredDataMessage extends MapMessage<StructuredDataMessage, Str
this
.
message
=
msg
;
}
@Override
protected
void
validate
(
final
String
key
,
final
String
value
)
{
validateKey
(
key
);
}
private
void
validateKey
(
final
String
key
)
{
if
(
key
.
length
()
>
MAX_LENGTH
)
{
throw
new
IllegalArgumentException
(
"Structured data keys are limited to 32 characters. key: "
+
key
);
}
for
(
int
i
=
0
;
i
<
key
.
length
();
i
++)
{
final
char
c
=
key
.
charAt
(
i
);
if
(
c
<
'!'
||
c
>
'~'
||
c
==
'='
||
c
==
']'
||
c
==
'"'
)
{
throw
new
IllegalArgumentException
(
"Structured data keys must contain printable US ASCII characters"
+
"and may not contain a space, =, ], or \""
);
}
}
}
/**
* Formats the structured data as described in RFC 5424.
*
...
...
@@ -415,45 +384,87 @@ public class StructuredDataMessage extends MapMessage<StructuredDataMessage, Str
protected
void
validate
(
String
key
,
boolean
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
byte
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
char
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
byt
e
value
)
{
protected
void
validate
(
String
key
,
doubl
e
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
shor
t
value
)
{
protected
void
validate
(
String
key
,
floa
t
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
Objec
t
value
)
{
protected
void
validate
(
String
key
,
in
t
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
f
lo
at
value
)
{
protected
void
validate
(
String
key
,
lo
ng
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
double
value
)
{
protected
void
validate
(
String
key
,
Object
value
)
{
validateKey
(
key
);
}
/**
* @since 2.9
*/
@Override
protected
void
validate
(
String
key
,
in
t
value
)
{
protected
void
validate
(
String
key
,
shor
t
value
)
{
validateKey
(
key
);
}
@Override
protected
void
validate
(
String
key
,
lo
ng
value
)
{
protected
void
validate
(
final
String
key
,
final
Stri
ng
value
)
{
validateKey
(
key
);
}
private
void
validateKey
(
final
String
key
)
{
if
(
key
.
length
()
>
MAX_LENGTH
)
{
throw
new
IllegalArgumentException
(
"Structured data keys are limited to 32 characters. key: "
+
key
);
}
for
(
int
i
=
0
;
i
<
key
.
length
();
i
++)
{
final
char
c
=
key
.
charAt
(
i
);
if
(
c
<
'!'
||
c
>
'~'
||
c
==
'='
||
c
==
']'
||
c
==
'"'
)
{
throw
new
IllegalArgumentException
(
"Structured data keys must contain printable US ASCII characters"
+
"and may not contain a space, =, ], or \""
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment