15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

log4jのログ出力先を取得する

Last updated at Posted at 2013-12-31

log4jの定義

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
	
<!-- File Appender -->
<appender name="file" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="/var/log/info.log" />
        <param name="MaxBackupIndex" value="10" />
		<param name="MaxFileSize" value="10MB" />
		<param name="Append" value="true" />
        <param name="Encoding" value="UTF-8" />
        <layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{yyyy/MMM/dd HH:mm:ss.SSS} [%-5p] %m%n" />
        </layout>
</appender>

<!-- Logger -->
<category name=“jp.co.xxx” additivity="false">
	<priority value="debug" />
	<appender-ref ref="file" />
</category>

</log4j:configuration>

出力先の取得

//カテゴリ名を取得してLoggerを取得
Logger logger = Logger.getLogger("jp.co.xxx");
// File Appenderを取得
FileAppender appender = (FileAppender)logger.getAppender("file");
//getFileでファイル出力場所が取得できる。
System.out.println(appender.getFile());

実行結果

/var/log/info.log

setFileでファイル出力先を指定することもできる。

15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?