As we all know, p6spy print out of the log is a long and long content, it is not easy to see, cow b p6spy Why can not think hibernate that has format_sql function?
No, I had to do it myself. Write a log output class, here I only cite the console log output example:
1 Packagecom.techmango.higenericdao.utils;2 3 ImportCom.p6spy.engine.spy.appender.StdoutLogger;4 5 Public classP6spystdoutloggerextendsStdoutLogger {6 Public voidLogText (String text) {7StringBuilder SB =NewStringBuilder ();8 //match to Last | as delimiter9string[] arrstring = Text.split ("\\| (?! [^\\|] *\\|)");Ten if(Arrstring.length > 1) { OneSb.append (arrstring[0]); A //go to the last paragraph of the statement to do the substitution for formatting -ARRSTRING[1] = Arrstring[1].replaceall (",", ", \r\n\t"); -ARRSTRING[1] = Arrstring[1].replaceall ("Values", ", \r\nvalues\r\n\t"); theARRSTRING[1] = Arrstring[1].replaceall ("from", "\r\nfrom\r\n\t"); -ARRSTRING[1] = Arrstring[1].replaceall ("where", "\r\nwhere\r\n\t"); -ARRSTRING[1] = Arrstring[1].replaceall ("ORDER By", "\r\norder by\r\n\t"); -ARRSTRING[1] = Arrstring[1].replaceall ("GROUP By", "\r\ngroup by\r\n\t"); +Sb.append ("\ r \ n"); -Sb.append (arrstring[1]); + qlog.println (sb.tostring ()); A } at Else { - qlog.println (text); - } -Arrstring =NULL; - } -}
Configure this class P6spystdoutlogger in the P6spy.properties file,
The printing results are as follows:
A- Geneva A:Panax Notoginseng: -,379| $|Statement|Connection3|Insert intoGas.news (title, Content, Icon, IMG, time, type, subtype, newsrange, keyword)Values (?, ?, ?, ?, ?, ?, ?, ?, ?)Insert intogas.news (title, Content, Icon, IMG, time, type, subtype, newsrange, keyword),Values ('to actually', 'Hibernate News', NULL, NULL, '02-12 months -15', '1', NULL, '1', NULL) A- Geneva A:Panax Notoginseng: -,488| -|rollback|Connection3||
How about this content is not easy to read it?
Format the output log of the P6spy