「Spring」インターフェース Logでエラーレベルメッセージを記録

2021年10月21日

説明
public interface Log
LogFactory によって正常にインスタンス化するには、このインターフェースを実装するクラスに、
このログの「名前」を表す単一の文字列パラメーターを受け取るコンストラクターが必要です。

error(Object message)
エラーログレベルでメッセージを記録します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class UserForm {
/* ログ処理用オブジェクト*/
private static Log log = LogFactory.getLog(UserForm.class);
public String getInfo() {
try(InputStream ism = this.getClass().getClassLoader().getResourceAsStream(xxx);
InputStreamReader isr = new InputStreamReader(ism,Charset.forName("UTF-8"));)
{
//処理コード
} catch (IOException e){
log.error(e)
return "";
}
}
}
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class UserForm { /* ログ処理用オブジェクト*/ private static Log log = LogFactory.getLog(UserForm.class); public String getInfo() { try(InputStream ism = this.getClass().getClassLoader().getResourceAsStream(xxx); InputStreamReader isr = new InputStreamReader(ism,Charset.forName("UTF-8"));) { //処理コード } catch (IOException e){ log.error(e) return ""; } } }
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class UserForm {

 /* ログ処理用オブジェクト*/
  private static Log log = LogFactory.getLog(UserForm.class);
  
  public String getInfo() {
  
   try(InputStream ism = this.getClass().getClassLoader().getResourceAsStream(xxx);
          InputStreamReader isr = new InputStreamReader(ism,Charset.forName("UTF-8"));)
              {
            //処理コード
   } catch (IOException e){
     log.error(e)
       return "";
   }
  
  }

}

 

SpringMVC

Posted by arkgame