use of org.apache.logging.log4j.core.config.Configuration in project vertigo by KleeGroup.
the class SocketLoggerAnalyticsConnectorPlugin method createLogger.
private static Logger createLogger(final String loggerName, final String hostName, final int port) {
// If it doesn't exist we create it with the right appender
final Logger logger = LogManager.getLogger(loggerName);
// we create appender
final SocketAppender appender = SocketAppender.newBuilder().withName("socketAnalytics").withLayout(SerializedLayout.createLayout()).withHost(hostName).withPort(port).withReconnectDelayMillis(// we make only one try
0).build();
appender.start();
// on ne close pas : car ca stop le context
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
config.getLoggerConfig(loggerName).addAppender(appender, null, null);
Configurator.setLevel(loggerName, Level.INFO);
return logger;
}
use of org.apache.logging.log4j.core.config.Configuration in project mule by mulesoft.
the class LoggerContextConfigurer method configureMonitor.
private void configureMonitor(MuleLoggerContext context) {
Configuration configuration = context.getConfiguration();
File configFile = null;
if (context.getConfigFile() != null) {
configFile = new File(context.getConfigFile().getPath());
} else if (!StringUtils.isEmpty(configuration.getName())) {
configFile = new File(configuration.getName());
}
if (configFile != null && configuration instanceof Reconfigurable) {
configuration.getWatchManager().setIntervalSeconds(DEFAULT_MONITOR_INTERVAL_SECS);
FileWatcher watcher = new ConfiguratonFileWatcher((Reconfigurable) configuration, getListeners(configuration));
configuration.getWatchManager().watchFile(configFile, watcher);
}
}
use of org.apache.logging.log4j.core.config.Configuration in project xian by happyyangyuan.
the class GelfLog4j2Init method addAppender.
/**
* add the gelf-log4j2 appender into log4j2 context.
*/
private void addAppender() {
final LoggerContext context = LoggerContext.getContext(false);
final Configuration defaultConfig = context.getConfiguration();
String gelfInputUrl = EnvUtil.isLan() ? XianConfig.get("gelfInputLanUrl") : XianConfig.get("gelfInputInternetUrl");
System.out.println("gelfInputUrl=" + gelfInputUrl);
int gelfInputPort = XianConfig.getIntValue("gelfInputPort");
if (StringUtil.isEmpty(gelfInputUrl) || gelfInputPort <= 0) {
System.out.println("Gelf input url or port is not properly configured. No log will be sent to gelf logger server.");
return;
}
final GelfLogAppender appender = /* WriterAppender.createAppender(layout, null, writer, writerName, false, true)*/
GelfLogAppender.createAppender(defaultConfig, "gelf", LevelRangeFilter.createFilter(Level.OFF, Level.INFO, Filter.Result.ACCEPT, null), new GelfLogField[] { new GelfLogField("environment", EnvUtil.getEnv(), null, null), new GelfLogField("application", EnvUtil.getApplication(), null, null), new GelfLogField("pid", JavaPIDUtil.getProcessName(), null, null), new GelfLogField("nodeId", LocalNodeManager.LOCAL_NODE_ID, null, null), new GelfLogField("thread", null, null, PatternLayout.newBuilder().withAlwaysWriteExceptions(false).withPattern("%t").build()), new GelfLogField("logger", null, null, PatternLayout.newBuilder().withAlwaysWriteExceptions(false).withPattern("%c").build()), new GelfLogField("msgId", null, "msgId", null) }, null, null, gelfInputUrl, null, gelfInputPort + "", null, "false", null, null, "gelf-log4j2", // only works when extractStackTrace is true
"true", null, null, null, true, "%p %m%n", MessageFormatEnum.json);
if (appender == null)
throw new RuntimeException("gelf-log4j2 fails to initialize.");
appender.start();
defaultConfig.addAppender(appender);
updateLoggers(appender, defaultConfig);
}
use of org.apache.logging.log4j.core.config.Configuration in project meghanada-server by mopemope.
the class Main method main.
public static void main(String[] args) throws ParseException, IOException {
final String version = getVersion();
System.setProperty("meghanada-server.version", version);
final Options options = buildOptions();
final CommandLineParser parser = new DefaultParser();
final CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("meghanada server : " + version, options);
return;
}
if (cmd.hasOption("version")) {
System.out.println(version);
return;
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("shutdown server");
Config.showMemory();
}));
System.setProperty("home", Config.getInstalledPath().getParentFile().getCanonicalPath());
addFileAppender();
if (cmd.hasOption("v")) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.DEBUG);
context.updateLoggers();
System.setProperty("log-level", "DEBUG");
log.debug("set verbose flag(DEBUG)");
}
if (cmd.hasOption("vv")) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.TRACE);
context.updateLoggers();
System.setProperty("log-level", "TRACE");
log.debug("set verbose flag(TRACE)");
}
if (cmd.hasOption("clear-cache")) {
System.setProperty("clear-cache-on-start", "true");
}
if (cmd.hasOption("gradle-version")) {
final String gradleVersion = cmd.getOptionValue("gradle-version", "");
if (!version.isEmpty()) {
System.setProperty("meghanada.gradle-version", gradleVersion);
}
}
String port = "55555";
String projectRoot = "./";
String fmt = "sexp";
if (cmd.hasOption("p")) {
port = cmd.getOptionValue("p", port);
}
if (cmd.hasOption("r")) {
projectRoot = cmd.getOptionValue("r", projectRoot);
}
if (cmd.hasOption("output")) {
fmt = cmd.getOptionValue("output", fmt);
}
log.debug("set port:{}, projectRoot:{}, output:{}", port, projectRoot, fmt);
final int portInt = Integer.parseInt(port);
log.info("Meghanada-Server Version:{}", version);
final Server server = createServer("localhost", portInt, projectRoot, fmt);
server.startServer();
}
use of org.apache.logging.log4j.core.config.Configuration in project meghanada-server by mopemope.
the class Main method addFileAppender.
private static void addFileAppender() throws IOException {
final String tempDir = System.getProperty("java.io.tmpdir");
final File logFile = new File(tempDir, "meghanada_server.log");
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
final FileAppender fileAppender = FileAppender.newBuilder().withName("file").withLayout(PatternLayout.newBuilder().withPattern("[%d][%-5.-5p][%-14.-14c{1}:%4L] %-22.-22M - %m%n").build()).withFileName(logFile.getCanonicalPath()).build();
configuration.addAppender(fileAppender);
loggerConfig.addAppender(fileAppender, Level.ERROR, null);
context.updateLoggers();
}
Aggregations