Format the output log of the P6spy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.