-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported markers rewrite to 3.x (#2584)
- Loading branch information
Showing
9 changed files
with
371 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/site/antora/modules/ROOT/examples/manual/markers/MarkerExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package example; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.MarkerManager; | ||
|
||
public final class MarkerExample { | ||
|
||
private static final Logger logger = LogManager.getLogger("example.MarkerExample"); | ||
// tag::create-marker[] | ||
private static final Marker SQL_MARKER = MarkerManager.getMarker("SQL"); | ||
// end::create-marker[] | ||
// tag::create-marker-parent[] | ||
private static final Marker QUERY_MARKER = | ||
MarkerManager.getMarker("SQL_QUERY").addParents(SQL_MARKER); | ||
private static final Marker UPDATE_MARKER = | ||
MarkerManager.getMarker("UPDATE").addParents(SQL_MARKER); | ||
// end::create-marker-parent[] | ||
|
||
public static void main(final String[] args) { | ||
doQuery("my_table"); | ||
doQueryParent("my_table"); | ||
doUpdate("my_table", "column", "value"); | ||
} | ||
|
||
public static void doQuery(String table) { | ||
// Do business logic here | ||
// tag::use-marker[] | ||
logger.debug(SQL_MARKER, "SELECT * FROM {}", table); | ||
// end::use-marker[] | ||
} | ||
|
||
public static void doQueryParent(String table) { | ||
// Do business logic here | ||
// tag::use-marker-parent[] | ||
logger.debug(QUERY_MARKER, "SELECT * FROM {}", table); | ||
// end::use-marker-parent[] | ||
} | ||
|
||
public static void doUpdate(String table, String column, String value) { | ||
// Do business logic here | ||
// tag::use-marker-parent[] | ||
logger.debug(UPDATE_MARKER, "UPDATE {} SET {} = {}", table, column, value); | ||
// end::use-marker-parent[] | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/site/antora/modules/ROOT/examples/manual/markers/log4j2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"Configuration": { | ||
"Appenders": { | ||
"Console": { | ||
"name": "SQL_LOG", | ||
"PatternLayout": { | ||
"pattern": "%d{HH:mm:ss.SSS} (%marker) %m%n" | ||
} | ||
} | ||
}, | ||
"Loggers": { | ||
"Root": { | ||
"level": "INFO" | ||
}, | ||
// tag::logger[] | ||
"Logger": { | ||
"name": "example", | ||
"level": "ALL", // <1> | ||
"AppenderRef": { | ||
"ref": "SQL_LOG", | ||
"MarkerFilter": { // <2> | ||
"marker": "SQL", | ||
"onMatch": "ACCEPT", | ||
"onMismatch": "DENY" | ||
} | ||
} | ||
} | ||
// end::logger[] | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/site/antora/modules/ROOT/examples/manual/markers/log4j2.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to you under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
appender.0.type = Console | ||
appender.0.name = SQL_LOG | ||
appender.0.layout.type = PatternLayout | ||
appender.0.layout.pattern = %d{HH:mm:ss.SSS} (%marker) %m%n | ||
|
||
rootLogger.level = INFO | ||
|
||
# tag::logger[] | ||
logger.0.name = example | ||
# <1> | ||
logger.0.level = ALL | ||
logger.0.appenderRef.0.ref = SQL_LOG | ||
# <2> | ||
logger.0.appenderRef.0.filter.type = MarkerFilter | ||
logger.0.appenderRef.0.filter.marker = SQL | ||
logger.0.appenderRef.0.filter.onMatch = ACCEPT | ||
logger.0.appenderRef.0.filter.onMismatch = DENY | ||
# end::logger[] |
43 changes: 43 additions & 0 deletions
43
src/site/antora/modules/ROOT/examples/manual/markers/log4j2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to you under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<Configuration xmlns="https://logging.apache.org/xml/ns" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
https://logging.apache.org/xml/ns | ||
https://logging.apache.org/xml/ns/log4j-config-2.xsd"> | ||
|
||
<appenders> | ||
<Console name="SQL_LOG"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} (%marker) %m%n"/> | ||
</Console> | ||
</appenders> | ||
|
||
<loggers> | ||
<root level="INFO"/> | ||
<!-- tag::logger[] --> | ||
<logger name="example" level="ALL"><!--1--> | ||
<AppenderRef ref="SQL_LOG"> | ||
<MarkerFilter marker="SQL" | ||
onMatch="ACCEPT" | ||
onMismatch="DENY"/><!--2--> | ||
</AppenderRef> | ||
</logger> | ||
<!-- end::logger[] --> | ||
</loggers> | ||
|
||
</Configuration> |
36 changes: 36 additions & 0 deletions
36
src/site/antora/modules/ROOT/examples/manual/markers/log4j2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to you under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
Configuration: | ||
Appenders: | ||
Console: | ||
name: "SQL_LOG" | ||
PatternLayout: | ||
pattern: "%d{HH:mm:ss.SSS} (%marker) %m%n" | ||
Loggers: | ||
Root: | ||
level: "INFO" | ||
# tag::logger[] | ||
Logger: | ||
name: "example" | ||
level: "ALL" # <1> | ||
AppenderRef: | ||
ref: "SQL_LOG" | ||
MarkerFilter: # <2> | ||
marker: "SQL" | ||
onMatch: "ACCEPT" | ||
onMismatch: DENY | ||
# end::logger[] |
23 changes: 23 additions & 0 deletions
23
src/site/antora/modules/ROOT/examples/manual/markers/marker-filtering.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to you under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# tag::use-marker[] | ||
10:42:30.982 (SQL) SELECT * FROM my_table | ||
# end::use-marker[] | ||
# tag::use-marker-parent[] | ||
10:42:30.982 (SQL_QUERY[ SQL ]) SELECT * FROM my_table | ||
10:42:30.982 (SQL_UPDATE[ SQL ]) UPDATE my_table SET column = value | ||
# end::use-marker-parent[] |
Oops, something went wrong.