Ajuda LOG4J

Pessoal estou precisando de ajuda, estou colocando o log4j no meu projeto… achei alguns exemplo bele.

fiz o seguinte log4j.properties

log4j.rootCategory = fileOut
log4j.appender.fileOut = org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileOut.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.fileOut.Append = true
log4j.appender.fileOut.File = example.log


log4j.appender.fileOut.layout = org.apache.log4j.PatternLayout
log4j.appender.fileOut.layout.ConversionPattern = [%d] %t %c{1} %-5p: %m%n

log4j.appender.fileOut.Threshold = ERROR[/code]


no meu main eu fiz o seguinte:[code]
   public class Main {
private static final Logger logger = Logger.getLogger(Main.class);
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BasicConfigurator.configure();

        try {
           // GerarCentraisNotas.gerarCentralCEP();
            //GerarCentraisNotas.escrever("oi", "tudo", "Bom");
            throw new Exception( "asss");
        } catch (Exception e) {
            e.printStackTrace();
        }
        }

nao teria ele q criar um exemplo.log ??? com esse erro q eu forcei???
ou eu etnho q toda fez q pode dar um erro… fazer alguma coisa
??

obrigado

[quote=fabioebner]Pessoal estou precisando de ajuda, estou colocando o log4j no meu projeto… achei alguns exemplo bele.

fiz o seguinte log4j.properties

log4j.rootCategory = fileOut
log4j.appender.fileOut = org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileOut.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.fileOut.Append = true
log4j.appender.fileOut.File = example.log


log4j.appender.fileOut.layout = org.apache.log4j.PatternLayout
log4j.appender.fileOut.layout.ConversionPattern = [%d] %t %c{1} %-5p: %m%n

log4j.appender.fileOut.Threshold = ERROR[/code]


no meu main eu fiz o seguinte:[code]
   public class Main {
private static final Logger logger = Logger.getLogger(Main.class);
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BasicConfigurator.configure();

        try {
           // GerarCentraisNotas.gerarCentralCEP();
            //GerarCentraisNotas.escrever("oi", "tudo", "Bom");
            throw new Exception( "asss");
        } catch (Exception e) {
            e.printStackTrace();
        }
        }

nao teria ele q criar um exemplo.log ??? com esse erro q eu forcei???
ou eu etnho q toda fez q pode dar um erro… fazer alguma coisa
??

obrigado[/quote]

   public class Main {
private static final Logger logger = Logger.getLogger(Main.class);
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BasicConfigurator.configure();

        try {
            throw new Exception( "asss");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Salvar essa mensagem no arquivo de log.txt");
        }
        }

Andre entao para cada classe eu tenho q fazer:

e no erro ologger.error("mensagem")
e pelo q eu estava vendo aqui essas opcoes log4j.appender.fileOut = org.apache.log4j.DailyRollingFileAppender log4j.appender.fileOut.DatePattern = '.'yyyy-MM-dd'.log'

nao tem q fazer ele gerar um arquivo de log com a data do dia???

[quote=fabioebner]Andre entao para cada classe eu tenho q fazer:

[/quote]

Sim

pode usar outros levels tb, como warn, debug, info, etc, dê uma olhada no manual

na verdade vc só precisa de algo parecido com isso

[quote]log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=teste.log
log4j.appender.R.DatePattern=’.'yyyy-MM-dd
[/quote]

Isso deve gerar o arquivo teste.log e toda vez que mudar o dia os arquivos serão copiados para o dia anterior, na sexta feira você terá

[quote]teste.2006-05-26.log
teste.2006-05-27.log
teste.2006-05-28.log
teste.log[/quote]