2017-02-16 52 views
0

我使用这个布局与RollingFileAppender的logback HTMLLayout页面太宽

一切都运行得很好,但这里有一个问题:通常所产生的表的像素宽度简直是太宽。

这是尤其如此,因为我的很多测试方法的名称通常是很长......他们熄灭了窗口的右边,我不得不经常向左和向右滚动。

我还使用(火狐)的NoSquint插件,在这里你几乎可以独立于“普通变焦”的缩放文字大小。但这并不真正奏效。我只是想规定每个表格列的最大值(和最小值,为什么不是?)像素宽度。

回答

0

任何有兴趣,我发现该溶液是在含有骆驼情况文本和/或点(也使文本更小)输出String s至插入HTML 软连字符­)。

- 修改logback.xml的logback-的test.xml文件内容如下:

<!-- <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> --> 
    <encoder class="utils.MyLayoutWrappingEncoder"> 
     <layout class="ch.qos.logback.classic.html.HTMLLayout"> 
      .... 

- 在LayoutWrapperEncoder文件从提取的logback源JAR复制和重命名为MyLayoutWrapperEncoder

- 修改了几个方法,在这个类

void writeHeader() throws IOException { 
    if (layout != null && (outputStream != null)) { 
     StringBuilder sb = new StringBuilder(); 
     appendIfNotNull(sb, layout.getFileHeader()); 
     appendIfNotNull(sb, layout.getPresentationHeader()); 
     if (sb.length() > 0) { 
      sb.append(CoreConstants.LINE_SEPARATOR); 

      // replace a couple of header names with shorter and smaller text    
      String outString = sb.toString(); 
      outString = outString.replaceAll("MethodOfCaller", "MoC").replaceAll("RelativeTime", "RT"); 
      outString = outString.replaceAll("LineOfCaller", "LoC"); 
      // make text smaller 
      outString = outString.replaceAll("<td class=(.+?)>", "<td style=\"font-size:13px\" class=$1>"); 

      outputStream.write(convertToBytes(outString)); 
      outputStream.flush(); 
     } 
    } 
} 

和:

public void doEncode(E event) throws IOException { 
    String txt = layout.doLayout(event); 

    /* 
    * Identify "camel case" upper case letters and also dots in all <TD> output... 
    * and insert soft hyphen at this point. Also make text smaller. 
    */ 
    Pattern tDPattern = Pattern.compile("<td class=.+?>(.*?)</td>"); 
    StringBuilder wholeStringSB = new StringBuilder(); 
    Matcher tDMatcher = tDPattern.matcher(txt); 
    int lastWholeString = 0; 
    while(tDMatcher.find()){ 
     String tDContents = tDMatcher.group(1); 
     Matcher camelCaseAndDotMatcher = Pattern.compile("[a-z]([A-Z\\.])").matcher(tDContents); 
     StringBuilder camelCaseAndDotSB = new StringBuilder(); 
     int last = 0; 
     while(camelCaseAndDotMatcher.find()){ 
      camelCaseAndDotSB.append(tDContents.substring(last, camelCaseAndDotMatcher.start(1))); 
      camelCaseAndDotSB.append("&shy;" + camelCaseAndDotMatcher.group(1)); 
      last = camelCaseAndDotMatcher.end(1); 
     } 
     if(last > 0){ 
      // ... at least one camel case UC char and/or dot WAS found... 
      wholeStringSB.append(txt.substring(lastWholeString, tDMatcher.start(1))); 
      camelCaseAndDotSB.append(tDContents.substring(last));  
      wholeStringSB.append(camelCaseAndDotSB.toString().trim()); 
      lastWholeString = tDMatcher.end(); 
     } 
    } 
    wholeStringSB.append(txt.substring(lastWholeString).trim()); 
    txt = wholeStringSB.toString(); 
    // make text smaller 
    txt = txt.replaceAll("<td class=(.+?)>", "<td style=\"font-size:13px\" class=$1>"); 


    outputStream.write(convertToBytes(txt)); 
    if (immediateFlush) 
     outputStream.flush(); 
} 

PS我还没有发现在哪里这些不同的TD为各种“类”的CSS属性元素的位置(或者,如果不是实际的文件,它们是如何生成的或其他)。有人知道吗?

PPS虽然有前途的方法,这些连字符似乎没有被应用到最后,“消息”,列。需要更多研究才能获得真正优秀的解决方