In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces Spring Boot combined with P6Spy case analysis, the content is very detailed, interested friends can refer to, hope to be helpful to you.
One: add dependencies to pom.xml
P6spy p6spy 3.8.0
Second: application.xml modifies the configuration of data sources
Spring: datasource: type: com.zaxxer.hikari.HikariDataSource url: jdbc:p6spy:mysql://... Username:... Password:... Driver-class-name: com.p6spy.engine.spy.P6SpyDriver
Three: configuration file spy.properties
Module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory# Custom Log Printing logMessageFormat=org.pkaq.core.log.P6SpyLogger# uses logging system logging sqlappender=com.p6spy.engine.spy.appender.Slf4JLogger## configuration logging Log exception excludecategories=info,debug,result,batc Resultset# setting uses p6spy driver as proxy deregisterdrivers=true# date format dateformat=yyyy-MM-dd HH:mm:ss# actually drives whether driverlist=com.mysql.jdbc.Driver# enables slow SQL recording outagedetection=true# slow SQL recording standard second outagedetectioninterval=2
Four: custom log printing
Implement MessageFormattingStrategy interface mode
Public class P6SpyLogger implements MessageFormattingStrategy {@ Overridepublic String formatMessage (int connectionId, String now, long elapsed, String category, String prepared, String sql) {return! ".equals (sql.trim ())?" ["+ LocalDateTime.now () +"]-- | took "+ elapsed +" ms | "+ category +" | connection "+ connectionId +"\ n "+ sql +"; ":";}}
two。 Specify the method in the spy.properties file
LogMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormatcustomLogMessageFormat=% (currentTime) | SQL time:% (executionTime) ms | connection information:% (category) -% (connectionId) | execute statement:% (sql)
5: detailed description of spy.properties parameters
# specify the log interception module of the application. The default is com.p6spy.engine.spy.P6SpyFactory # modulelist=com.p6spy.engine.spy.P6SpyFactory,com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory# real JDBC driver, and multiple are separated by commas. Default is empty. # driverlist=# whether to automatically refresh the default flase#autoflush=false# configuration SimpleDateFormat date format is empty by default # dateformat=# print stack trace information default flase#stacktrace=false# if stacktrace=true You can specify a specific class name for filtering. # stacktraceclass=# monitors whether the property configuration file is reloaded # reloadproperties=false# property configuration file reload interval (in seconds) default 60s#reloadpropertiesinterval=60# specifies the appender of Log, value: # appender=com.p6spy.engine.spy.appender.Slf4JLogger#appender=com.p6spy.engine.spy.appender.StdoutLogger#appender=com.p6spy.engine.spy.appender.FileLogger# specifies the file name of Log default spy.log#logfile=spy.log# specifies whether to add Log each time If it is set to false, the default true#append=true# will be cleared every time. The default log output style is com.p6spy.engine.spy.appender.SingleLineFormat, and the single-line output can also be customized using com.p6spy.engine.spy.appender.CustomLineFormat without formatting statement # logMessageFormat=com.p6spy.engine.spy.appender.SingleLineFormat#. The default value is% (currentTime) |% (executionTime) |% (category) | connection% (connectionId) |% (sqlSingleLine) # available variables are: #% (connectionId) connection id#% (currentTime) current time #% (executionTime) execution time #% (category) execution grouping #% (effectiveSql) Submitted SQL line feeds #% (effectiveSqlSingleLine) submitted SQL without line wrapping shows #% (sql) real SQL statements executed Replaced the real SQL statement executed by #% (sqlSingleLine) Replaced placeholder without wrapping display # customLogMessageFormat=% (currentTime) |% (executionTime) |% (category) | connection% (connectionId) |% (sqlSingleLine) # date format used for logging in date type field default dd-MMM-yy#databaseDialectDateFormat=dd-MMM-yy# boolean type field default date format default boolean optional value numeric#databaseDialectBooleanFormat=boolean# exposure property default true#jmx=true# if jmx is set Set to true specifies that the prefix when exposing attributes via jmx defaults to # com.p6spy (.): whether name=#jmxPrefix=# displays the nanosecond default false#useNanoTime=false# actual data source JNDI#realdatasource=/RealMySqlDS# actual data source datasourceclass # realdatasourceclass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource# actual data source the configuration parameters carried by the actual data source are specified to be separated by a semicolon # realdatasourceproperties=port 3306 JNDI data source configuration # sets the NamingContextFactory of the JNDI data source. # jndicontextfactory=org.jnp.interfaces.NamingContextFactory# sets the URL of the provider of the JNDI data source. # jndicontextproviderurl=localhost:1099# sets some customized information for JNDI data sources, separated by semicolons. # jndicontextcustom=java.naming.factory.url.pkgs Whether org.jboss.naming:org.jnp.interfaces# enables log filtering default false. Whether this configuration takes effect is provided that the list of table names contained in include/exclude/sqlexpression#filter=false# filtering Log is configured, and the list of table names excluded by default # include=# filtering Log is separated by comma. SQL regular expression name when filtering Log is empty by default # exclude=# separated by comma # sqlexpression=# displays the list of categories queued when filtering Log. Values: error, info, batch, debug, statement,#commit, rollback, result and resultset are valid values# (default info,debug,result,resultset,batch) # excludecategories=info,debug,result,resultset,batch# whether to filter binary field # (default is false) # excludebinary=false# P6Log module execution time setting The integer value (in milliseconds), after which the Log is recorded. Default is whether the 0#executionThreshold=# P6Outage module records statements that run for a long time. Default false# outagedetection=true | the execution time of the false# P6Outage module is set, and the integer value (in seconds). The Log is recorded only when this time is exceeded. Default 30s# outagedetectioninterval=integer time (seconds) on Spring Boot combined with P6Spy case analysis is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.