Èì.. À̱ÛÀº ¾ó¶³°á¿¡ ¾²°Ô µÇ´Â ¾ÆƼŬÀ̶ó ±×¸® ±æÁö ¾ÊÀ½À» ¸ÕÀú ¾Ë¸®¸ç, ÀüÈ«¼º´Ô°úÀÇ
´ëÈÁß¿¡ °á°ú°¡ ³ª¿Â °ÍÀ» ±Û·Î¼ Àû½À´Ï´Ù.
¢º µ¿±â
ÂË´Ô°úÀÇ ´ëÃæÀÇ ´ëȳ»¿ëÀ» »ìÆ캸¸é Log4j¸¦ ÀÌ¿ëÇϴµ¥ ÀÖ¾î¼ EJB Container°¡ A, B¿Í
°°ÀÌ 2°³°¡ ¶°ÀÖÀ» °æ¿ì A-Container¿¡¼´Â stdoutÀÎ console·Î±×¸¦ ³²±â°í, B-Container¿¡¼´Â
file¿¡ ·Î±×¸¦ ³²±â´Â °æ¿ì°¡ ÈçÈ÷ ¹ß»ýÀ» ÇÒ ¼ö ÀÖ¶ó´Â °ÍÀÌ´Ù.
±âÁ¸ÀÇ Á¦ ¾ÆƼŬÀ» È°¿ëÇÏ¿© Å×½ºÆ® ÇÏ·Á ÇßÀ¸³ª root¶ó´Â ¼Ó¼º¶§¹®¿¡ Áߺ¹±â·ÏÀ̶ó´Â
¹®Á¦°¡ ¹ß»ýÇÏ¿© ÇØ°áÁ¡À» ã±â À§ÇÔÀÌ µ¿±â¿´´Ù.
±âÁ¸ÀÇ ¾ÆƼŬÀ» ÀÐ°í ½Í´Ù¸é ¾Æ·¡ÀÇ ±ÛÀ» ¸ÕÀú Àб⠹ٶõ´Ù.
Log4j¸¦ À§ÇÑ ¿©·¯°¡Áö ȯ°æ¼³Á¤(xml property)
¢º XML ConfigurationÀÇ º¯È ¹× Å×½ºÆ® »ùÇÃÀÇ º¯È
¿©±â¼ Å×½ºÆ®ÇÏ°íÀÚ ÇÏ´Â °ÍÀº loggerÀÇ appender°¡ Ãß°¡µÇ¾úÀ» °æ¿ì °¢ Ŭ·¡½º ÆÄÀÏÀÌ
¼·Î ´Ù¸¥ (¿¹¸¦ µé¸é A.class´Â console¿¡, B.class´Â file¿¡ ·Î±×¸¦ ³²±â´Â °æ¿ì) ·Î±×¸¦ ´Ù¸¥
ÇüÅ·Π³²±â°íÀÚ ÇÒ¶§ »ç¿ëÇÏ·Á´Â °ÍÀÌ´Ù.
¿ì¼± ±âÁ¸ÀÇ fileConsole.xml config¸¦ º¸µµ·Ï ÇÏÀÚ.
<?xml version="1.0" encoding="euc-kr" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
ÆÄÀÏ¿¡ ·Î±×¸¦ ±â·ÏÇÏ´Â »ùÇÃÀÔ´Ï´Ù.
±âº»ÀûÀ¸·Î ·Î±×ÆÄÀÏÀÇ À̸§À» ±â·ÏÇÒ ¼ö ÀÖÀ¸¸ç
ÇØ´ç¼³Á¤Àº root logger¿¡ ¼³Á¤µÇ¾î ÀÖ´Â ³»¿ëÀ» ÂüÁ¶ÇÏ¿© ¼³Á¤ÀÌ °¡´ÉÇÕ´Ï´Ù.
Áï, ÆÄÀÏ°ú ÄַܼΠÁï½Ã Ãâ·ÂÀÌ °¡´ÉÇÏ¸ç °£´ÜÇÏ°Ô Å×½ºÆ®Çغ¼¼ö ÀÖ½À´Ï´Ù.
-->
<log4j:configuration>
<appender name="A1" class="org.apache.log4j.FileAppender">
<param name="File" value="fileConsole.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n"/>
</layout>
</appender>
<appender name="A2" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r %-5p [%t] %37c %3x - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="A1"/>
<appender-ref ref="A2"/>
</root>
</log4j:configuration>
|
À§¿¡¼ º¸°Ô µÇ¸é appender°¡ Á¤ÀÇ°¡ µÇ¾îÁö°í A1, A2ÀÇ appenderÀÇ ÇüÅ°¡ Çϳª´Â ÆÄÀÏÀÌ°í
Çϳª´Â ÄܼÖÀ» ÀÌ¿ëÇؼ Ãâ·ÂÀ» ³»º¸³¾ ¼ö ÀÖ°ÔÇϴµ¥ Ư¡Àº root element¿¡ ¼û°ÜÁ®ÀÖ´Ù.
root¼Ó¼ºÀ¸·Î¼ appender-ref¸¦ »ç¿ëÇÏ°Ô µÇ¸é ±âº»ÀûÀ¸·Î root°¡ °¡Áö°í ÀÖ´Â log¼Ó¼ºÀ» ±×´ë·Î
ÀÌ¿ëÇÏ¿© ó¸®ÇÏ°Ô µÇ¸ç, °¢°¢ÀÇ Logger °´Ã¼¸¦ ¾ò¾î³¾¶§ classÇüŶó´øÁö, StringÇüŵîÀÌ
ÇØ´ç LogRepository¿¡ µî·ÏµÇ¾î console, file¸ðµå¸¦ ¸ðµÎ »ç¿ëÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
¹®Á¦Á¡Àº logger°´Ã¼¸¦ Logger.getLogger() ¸Þ¼Òµå¸¦ ÅëÇØ ¾ò¾î³ÂÀ» ¶§ Ãâ·Â¹æÇâÀ» Á¦¾îÇÒ¼ö
¾ø´Ù¶ó´Â °ÍÀÌ´Ù.
±×·¸´Ù¸é ¾î¶»°Ô ¼öÁ¤À» ÇÏ°Ô µÇ¸é ½±°Ô 󸮰¡ µÇ¾îÁú ¼ö ÀÖÀ»±î?
±âº»ÀûÀ¸·Î log4j¿¡¼ Á¦°øÇÏ´Â ¹æ¹ýÀº category element¿Í logger element¸¦ Á¦°øÇÏ°í ÀÖ´Ù.
Áï root°¡ ¾Æ´Ñ logger tag³ª category tag¸¦ »ç¿ëÇؼ getLogger()¸Þ¼Òµå¸¦ »ç¿ëÇßÀ»¶§
³»°¡ ¿øÇÏ´Â ·Î±×ÇüŸ¸À» ¾ò¾î³¾¼ö ÀÖ´Â ¹æ¹ýÀÌ´Ù.
À§ÀÇ xmlÆÄÀÏÀ» ¼öÁ¤ÇÑ Àüü xml¸¦ º¸µµ·Ï ÇÏÀÚ.
<?xml version="1.0" encoding="euc-kr" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
ÆÄÀÏ¿¡ ·Î±×¸¦ ±â·ÏÇÏ´Â »ùÇÃÀÔ´Ï´Ù.
±âº»ÀûÀ¸·Î ·Î±×ÆÄÀÏÀÇ À̸§À» ±â·ÏÇÒ ¼ö ÀÖÀ¸¸ç
ÇØ´ç¼³Á¤Àº root logger¿¡ ¼³Á¤µÇ¾î ÀÖ´Â ³»¿ëÀ» ÂüÁ¶ÇÏ¿© ¼³Á¤ÀÌ °¡´ÉÇÕ´Ï´Ù.
Áï, ÆÄÀÏ°ú ÄַܼΠÁï½Ã Ãâ·ÂÀÌ °¡´ÉÇÏ¸ç °£´ÜÇÏ°Ô Å×½ºÆ®Çغ¼¼ö ÀÖ½À´Ï´Ù.
-->
<log4j:configuration>
<appender name="FILE_LOGGER" class="org.apache.log4j.FileAppender">
<param name="File" value="fileConsole.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n"/>
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r %-5p [%t] %37c %3x - %m%n"/>
</layout>
</appender>
<logger name="a1">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="a2">
<appender-ref ref="FILE_LOGGER"/>
</logger>
<category name="fileLogger">
<priority value="info"/>
<appender-ref ref="FILE_LOGGER"/>
</category>
<category name="consoleLogger">
<priority value="info"/>
<appender-ref ref="CONSOLE"/>
</category>
</log4j:configuration>
|
¹Ù²ï°ÍÀ̶ó°í´Â logger tag¿Í category tagÀÇ Ãß°¡ ¹× rootÀÇ ¼Ó¼º¿ä¼Ò°¡ ¾ø¾îÁ³´Ù¶ó´Â °ÍÀÌ´Ù.
±×·¸´Ù¸é ÇÁ·Î±×·¥»ó¿¡¼ ÇØ´ç logger¸¸ »ç¿ëÇÏ°í ½ÍÀ» °æ¿ì´Â ¾îÂîÇÒ °ÍÀΰ¡?
´Ü¼øÈ÷ DOMConfigurator¿¡¼ ·ÎµùµÈ Logger°´Ã¼¿¡¼ ¾Æ·¡¿Í °°ÀÌ ¾²°í ½ÍÀº logger¸¦
¾ò¾î³»¸é ±×¸¸ÀÌ´Ù.
Logger logger = LogUtil.getLogger("consoleLogger");
À§¿¡¼ consoleLogger¸¦ ¾ò¾î³»°Ô µÇ¸é
<appender-ref ref="CONSOLE"/>
ÀÌ ÂüÁ¶µÇ°Ô µÇ¸é ÇØ´ç ³»¿ªÀÌ console¿¡ Ãâ·ÂÀÌ µÇ¾îÁú ¼ö ÀÖ°Ô ÇÑ´Ù.
ÀÚ ±×·¸´Ù¸é À§ÀÇ °æ¿ì´Â categoryÀÇ name¿¡ ¼³Á¤µÈ °ÍÀ» ¾ò¾î³Â´Âµ¥ °°Àº Ãâ·ÂÀ» ¾ò°Ô
ÇÏ·Á¸é ¾î¶»°Ô °íÄ¡¸é µÉ±î?
´ç¿¬È÷ logger tag¿¡ ÀÖ´Â appender¸¦ ÀÌ¿ëÇصµ µÉ°ÍÀÌ´Ù.
<logger name="a1">
À§ÀÇ logger¸¦ ÂüÁ¶ÇÏ°Ô ÇÑ´Ù¸é °á°ú°ªÀº °°°Ô ³ª¿Ã°ÍÀÌ´Ù.
Logger logger = LogUtil.getLogger("a1");
¢º Conclusion
°£´ÜÇÏ°Ô xml config¸¦ º¯°æÇÏ¿© ¿øÇÏ´Â °ÍÀ» ¾ò´Â °ÍÀ» Å×½ºÆ®ÇغÃÀ¸¸ç, ¿©·¯°¡ÁöÀÇ
Ãâ·Â¸ðµå°¡ Á¦°øµÇ°í ÀÖÀ¸¹Ç·Î ÀÔ¸À¿¡ ¸À°Ô º¯°æÇÏ¿© ¾²¸é ¹«¸®°¡ ¾øÀ¸¸®¶ó º»´Ù.
|