Completed log settings.

This commit is contained in:
Christian P. MOMON 2018-01-07 22:28:57 +01:00
parent 0475664083
commit 7437a8c03e
3 changed files with 37 additions and 69 deletions

View File

@ -1,39 +1,21 @@
log4j.rootLogger = warn, stdout
# Log information (priority setting : DEBUG < INFO < WARN < ERROR)
# http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
# ################
log4j.logger.org.april.hebdobot = info
log4j.rootLogger = INFO, stdout, LogWriter
log4j.logger.org.april.hebdobot = DEBUG
#--
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d %-5p %c - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern = %d{ISO8601} - Hebdobot [%-5p] %34.34c.%25M - %m%n
# Log information (priority setting : DEBUG < INFO < WARN < ERROR)
# ################
log4j.rootLogger = INFO, RSLisi-Writer, CONSOLE
log4j.logger.fr.devinsy.hico = DEBUG
log4j.logger.fr.devinsy.kiss4web = DEBUG
log4j.logger.fr.devinsy.xidyn = INFO
log4j.logger.fr.devinsy.xidyn.Presenter = INFO
log4j.logger.fr.devinsy.xidyn.FilePresenter = DEBUG
log4j.logger.eu.republiquesociale = DEBUG
#--
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d{ISO8601} - RSLisi [%-5p] %34.34c.%25M - %m%n
log4j.appender.stdout.layout.ConversionPattern = %m%n
#--
log4j.appender.RSLisi-Writer = org.apache.log4j.RollingFileAppender
log4j.appender.RSLisi-Writer.File = /services/RSLisi/rslisi.log
log4j.appender.RSLisi-Writer.MaxFileSize = 100000KB
log4j.appender.RSLisi-Writer.MaxBackupIndex = 100
log4j.appender.RSLisi-Writer.layout = org.apache.log4j.PatternLayout
log4j.appender.RSLisi-Writer.layout.ConversionPattern = %d{ISO8601} - RSLisi [%-5p] %-50c.%30M - %m%n
log4j.appender.LogWriter = org.apache.log4j.RollingFileAppender
log4j.appender.LogWriter.File = /srv/hebdobot/hebdobot.log
log4j.appender.LogWriter.MaxFileSize = 100000KB
log4j.appender.LogWriter.MaxBackupIndex = 5
log4j.appender.LogWriter.layout = org.apache.log4j.PatternLayout
log4j.appender.LogWriter.layout.ConversionPattern = %d{ISO8601} - HEBDOBOT [%-5p] %34.34c.%-25M - %m%n

View File

@ -19,10 +19,6 @@
*/
package org.april.hebdobot;
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.april.hebdobot.cli.HebdobotCLI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,21 +45,6 @@ public class HebdobotLauncher
*/
public static void main(final String[] args)
{
// Configure log.
File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists())
{
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
}
else
{
BasicConfigurator.configure();
logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
}
//
setDefaultException();

View File

@ -28,6 +28,8 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.april.hebdobot.HebdobotException;
import org.april.hebdobot.model.Hebdobot;
import org.april.hebdobot.model.UserAliases;
@ -79,6 +81,8 @@ public class HebdobotCLI
{
try
{
System.out.println("--------------------------------START-------------------------------------------");
//
Options options = new Options();
options.addOption("h", "help", false, "Help option");
@ -89,7 +93,6 @@ public class HebdobotCLI
if (commandLine.hasOption("h"))
{
logger.debug("Help requires.");
help();
HelpFormatter formatter = new HelpFormatter();
@ -101,7 +104,7 @@ public class HebdobotCLI
File configFile;
if (commandLine.hasOption("c"))
{
logger.debug("'-c' option detected with value [{}].", commandLine.getOptionValue("c"));
System.out.println(String.format("'-c' option detected with value [%s].", commandLine.getOptionValue("c")));
// Check configuration file.
String value = commandLine.getOptionValue("c");
@ -116,7 +119,7 @@ public class HebdobotCLI
}
else
{
logger.debug("'-c' option NOT detected.");
System.out.println("'-c' option NOT detected.");
// Try to load default configuration file in current work
// directory.
@ -126,38 +129,31 @@ public class HebdobotCLI
if (configFile.exists())
{
/*
//
File loggerConfigFile = new File(configFile, "log4j.properties");
// Init log file.
File loggerConfigFile = new File(configFile.getParent(), "log4j.properties");
if (loggerConfigFile.exists())
{
PropertyConfigurator.configure(loggerConfigFile.getAbsolutePath());
logger.info("--==============================INIT==========================================--");
logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfigFile.getAbsoluteFile());
logger.info("Configuration log file was found in [{}].", loggerConfigFile.getAbsoluteFile());
}
else
{
BasicConfigurator.configure();
logger.info("--==============================INIT==========================================--");
logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfigFile.getAbsoluteFile());
}*/
}
// Load configuration file.
logger.info("Config file loading… ({}).", configFile.getAbsolutePath());
logger.info("Configuration file loading… ({}).", configFile.getAbsolutePath());
HebdobotConfigFile config = new HebdobotConfigFile(configFile);
logger.info("Config file loaded.");
// Load user aliases file.
File aliasFile = new File(configFile.getParentFile(), DEFAULT_ALIAS_FILE);
logger.info("Aliases file loading… ({}).", aliasFile.getAbsolutePath());
UserAliases aliases = new UserAliases(aliasFile);
logger.info("Aliases file loaded (" + aliases.size() + " aliases).");
logger.info("Alias liste:\n" + aliases.toString());
logger.info("Configuration file loaded.");
if (config.isValid())
{
logger.info("Bot configuring…");
//
File reviewDirectory;
if (config.getReviewDirectory() == null)
{
@ -172,9 +168,18 @@ public class HebdobotCLI
reviewDirectory = new File(configFile.getParentFile(), config.getReviewDirectory());
}
// Load user aliases file.
File aliasFile = new File(configFile.getParentFile(), DEFAULT_ALIAS_FILE);
logger.info("Aliases file loading… ({}).", aliasFile.getAbsolutePath());
UserAliases aliases = new UserAliases(aliasFile);
logger.info("Aliases file loaded (" + aliases.size() + " aliases).");
logger.info("Alias liste:\n" + aliases.toString());
Hebdobot bot = new Hebdobot(config.getIrcHost(), config.getIrcPort(), config.getIrcName(), config.getIrcChannel(),
configFile.getParentFile(), reviewDirectory, config.getReviewFileSuffix());
//
logger.info("Bot configuring…");
bot.getPastebinSettings().setApiKey(config.getPastebinApiKey());
bot.getIdenticaSettings().setApiKey(config.getIdenticaApiKey());
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());