Grails 2.4.3将FATAL日志级别视为ERROR

时间:2014-10-15 15:47:03

标签: log4j

我正在学习Grails中的log4j配置。以下是我的Config.groovy。记录器grails.app.controllers.logging.FatalController配置为仅记录致命级别。

log4j.main = {
    // Example of changing the log pattern for the default console appender:
    //
    //appenders {
    //    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
    //}

    fatal 'grails.app.controllers.logging.FatalController'

    error  'org.codehaus.groovy.grails.web.servlet',        // controllers
           'org.codehaus.groovy.grails.web.pages',          // GSP
           'org.codehaus.groovy.grails.web.sitemesh',       // layouts
           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping',        // URL mapping
           'org.codehaus.groovy.grails.commons',            // core / classloading
           'org.codehaus.groovy.grails.plugins',            // plugins
           'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
           'org.springframework',
           'org.hibernate',
           'net.sf.ehcache.hibernate'

    warn 'grails.app.services.logging.WarnService',
         'grails.app.controllers.logging.WarnController'

这是我的FatalController.groovy:

package logging

class FatalController {
        def index(){
                log.debug("This is not shown")
                log.warn("neither this")
                log.error("or that")
                log.fatal("but this does")

                render "logged"
        }
}

现在,当我执行此操作时,我希望它能够记录"但这样做"。然而,它并没有。当我更改Config.groovy行时:

fatal 'grails.app.controllers.logging.FatalController'

到此:

all 'grails.app.controllers.logging.FatalController'

我得到的输出是:

2014-10-15 12:33:04,070 [http-bio-8080-exec-2] DEBUG logging.FatalController  - This is not shown
2014-10-15 12:33:04,071 [http-bio-8080-exec-2] WARN  logging.FatalController  - neither this
| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController  - or that
| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController  - but this does

请注意消息"但是这样做"在FatalController.groovy中定义为以致命

记录
log.fatal("but this does")

日志消息说的是它是一个ERROR级别的消息日志:

| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController  - but this does

所以有两个问题:1)当记录器级别定义为FATAL时,不显示FATAL日志消息; 2)当我编写log.fatal("某些")时,日志显示为一个ERROR级别的消息。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为这是Grails错误(我正在使用Grails 2.4.5)。

我找到了一种解决方法:尝试以“旧方式”使用log4j。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style>
      table {
        border-collapse: collapse;
      }

      table, td, th {
        border: 1px solid black;
      }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
  </head>

  <body>

  <?php
    ini_set('error_reporting', E_ALL);
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "pacra1";

    $conn = new mysqli($servername, $username, $password, $dbname);

    $sql = "SELECT * FROM `letter_copy` WHERE `id` = 1";

    $conn->multi_query($sql);

    //$conn->next_result();

    $result = $conn->use_result();

    echo $conn->error; 
    $row = $result->fetch_assoc();

    $opinion = $row['opinion'];
    $action = $row['action'];

    $opinion_chunks = explode(",", $opinion);

  ?>
  <div style="margin-top:auto; width:auto;font-family:'Times New Roman', Times, serif; text-align:left; font-size:12px; text-align:center">
    <table width="657">
      <tr>
        <td width="225"> <strong>Opinion</strong></td>
        <td width="62"> <strong>Action</strong></td>
        <td colspan="4"><strong>Ratings</strong></td>
        <td width="54"><strong>Outlook</strong></td>
        <td width="67"><strong>Rating Type</strong></td>
      </tr>
      <tr>
        <td width="225">&nbsp;</td>
        <td width="62">&nbsp;</td>
        <td colspan="2"><b>Long Term</b></td>
        <td colspan="2"><b>Short Term</b></td>
        <td width="54">&nbsp;</td>
        <td width="67">&nbsp;</td>
      </tr>
      <tr>
        <td width="225">&nbsp;</td>
        <td width="62">&nbsp;</td>
        <td width="52"><b>Current</b></td>
        <td width="45"><b>Previous</b></td>
        <td width="49"><b>Current</b></td>
        <td width="51"><b>Previous</b></td>
        <td width="54">&nbsp;</td>
        <td width="67">&nbsp;</td>
      </tr>
    </table>
  </div>
  <?php

    echo '<table border="01">';
    foreach($opinion_chunks as $row){
      echo '<tr>';
      $row = explode(',',$row);
      $row1 = explode(",", $action);
      foreach($row as $cell){
        if ($cell == "")
          continue;
          echo '<td>';
          echo $cell;
          echo '</td>';
          foreach($row1 as $cell1){
            if ($cell1 == "")
              continue;
              echo '<td>';
              echo $cell1;
              echo '</td>';
          }
      }
      echo '</tr>';
    }
    echo '</table>';
  ?>

  </body>
</html>