本文整理汇总了Java中uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J类的典型用法代码示例。如果您正苦于以下问题:Java SysOutOverSLF4J类的具体用法?Java SysOutOverSLF4J怎么用?Java SysOutOverSLF4J使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SysOutOverSLF4J类属于uk.org.lidalia.sysoutslf4j.context包,在下文中一共展示了SysOutOverSLF4J类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logSysout
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
private static void logSysout(boolean isError, String text, Object... args) {
StringBuilder sb = new StringBuilder();
String level = isError ? "E" : "I";
if (false == SysOutOverSLF4J.systemOutputsAreSLF4JPrintStreams()) {
sb.append(LocalDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")));
sb.append(' ').append(level);
sb.append(" [main]").append(Classes.shortCanonicalName(Slf4js.class)).append(": ");
}
sb.append(text).append(System.lineSeparator());
(isError ? System.err : System.out).format(sb.toString(), args);
sb = null;
}
示例2: doStartup
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
/**
* Initializes the MainWindow.
*
* @wbp.parser.entryPoint
*/
private void doStartup() {
// Redirect System.out calls to logger
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
// Setup our look and feel
Platform.setLookAndFeel();
// Initialize application
frame = new JFrame();
frame.getRootPane().setFocusable(false);
App.init(frame);
ChartPropertiesDialog.setChartPreferencesToDefaults();
initGUI();
UpdateChecker uc = new UpdateChecker();
uc.programmaticCheckForUpdates();
}
示例3: main
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J(LogLevel.INFO,LogLevel.INFO);
runTask("db", "run", "-s", "scripts/other/drop.sql", "src/test/resources/test.create.yaml");
runTask("db", "run", "--script", "scripts/changelog/createSchemaVersionTable.mysql.sql", "src/test/resources/test.yaml");
runTask("db", "upgrade", "src/test/resources/test.yaml");
runTask("db", "upgrade", "src/test/resources/test.yaml");
}
示例4: setupConsoleLogging
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
/**
* Sets up SLF4J logging for {@link System#out} and {@link System#err} at INFO level.
* The logger also logs to {@link ClientSettings#LOGGING_FILE}, with the same format as for the console.
*/
private static void setupConsoleLogging() {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);
ConsoleAppender<ILoggingEvent> consoleAppender =
(ConsoleAppender<ILoggingEvent>) root.getAppender("console");
LayoutWrappingEncoder<ILoggingEvent> consoleWrappingEncoder =
(LayoutWrappingEncoder<ILoggingEvent>) consoleAppender.getEncoder();
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setLayout(consoleWrappingEncoder.getLayout());
encoder.setCharset(Charset.forName("UTF-16"));
encoder.setContext(root.getLoggerContext());
encoder.start();
FileAppender<ILoggingEvent> logFileAppender = new FileAppender<>();
logFileAppender.setFile(ClientSettings.LOGGING_FILE);
logFileAppender.setContext(root.getLoggerContext());
logFileAppender.setEncoder(encoder);
logFileAppender.setAppend(false);
logFileAppender.start();
root.addAppender(logFileAppender);
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
示例5: configureLogging
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
/**
* Customize logging of the application as necessary.
*/
private void configureLogging() {
if (!HAS_CONSOLE) {
SysOutOverSLF4J.registerLoggingSystem("org.ops4j.pax.logging.slf4j");
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
if (HAS_JUL_BRIDGE) {
org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger();
org.slf4j.bridge.SLF4JBridgeHandler.install();
}
}
示例6: switchLogging
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
private void switchLogging() {
if (this.useSlf4j) {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
Logger.getLogger("PIT").addHandler(new SLF4JBridgeHandler());
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
}
示例7: loadConfigs
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
public static void loadConfigs(URL url) {
if (null == url) {
logSyserr("fail to configure logger: <null path>");
return;
}
logSysout("JVM Default Charset: %s", Charset.defaultCharset().name());
if (false == Charset.defaultCharset().equals(Charsets.UTF_8))
logSysout("If charset is broken, Try this jvm option: '-Dfile.encoding=utf-8'");
ILoggerFactory lf = LoggerFactory.getILoggerFactory();
// XXX 현재는 logback만 지원함.
if (lf instanceof LoggerContext) {
LoggerContext lc = (LoggerContext) lf;
boolean isLoaded = (System.currentTimeMillis() - lc.getBirthTime()) >= 500L;
logSysout("configure logger (slf4j->logback): <%s> %s", url.toString(), (isLoaded ? "(overwrite)" : ""));
JoranConfigurator configurator = new JoranConfigurator();
try {
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(url);
} catch (Throwable t) {
logSyserr("fail to configure logger (slf4j->logback): <%s>", url.toString());
return;
}
} else {
logSyserr("fail to configure logger (slf4j->?): <%s> is not supported. ", lf.getClass().getName());
return;
}
java.util.logging.Logger jul = LogManager.getLogManager().getLogger("");
for (Handler handler : jul.getHandlers()) {
jul.removeHandler(handler);
}
SLF4JBridgeHandler.install();
logSysout("configure logger (jul->slf4j)");
if (false == SysOutOverSLF4J.systemOutputsAreSLF4JPrintStreams()) {
LogLevel sysout = LogLevel.DEBUG, syserr = LogLevel.ERROR;
logSysout("configure logger (sysout->slf4j): sysout=%s, syserr=%s", sysout.name(), syserr.name());
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J(sysout, syserr);
}
}
示例8: initLoggerContext
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
@PostConstruct
public void initLoggerContext() {
// properties of the LoggerContext
List<ImmutablePair<String, String>> properties = Arrays.asList(
new ImmutablePair<>(SakuliProperties.LOG_FOLDER, sakuliProperties.getLogFolder().toAbsolutePath().toString()),
new ImmutablePair<>(SakuliProperties.LOG_PATTERN, sakuliProperties.getLogPattern()),
new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SAKULI, sakuliProperties.getLogLevelSakuli()),
new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SAHI, sakuliProperties.getLogLevelSahi()),
new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SIKULI, sakuliProperties.getLogLevelSikuli()),
new ImmutablePair<>(SakuliProperties.LOG_LEVEL_SPRING, sakuliProperties.getLogLevelSpring()),
new ImmutablePair<>(SakuliProperties.LOG_LEVEL_ROOT, sakuliProperties.getLogLevelRoot())
);
//log new properties before configuring
properties.stream().filter(p -> isNotEmpty(p.getValue()))
.forEach(p -> logger.info("set '{}' to '{}'", p.getKey(), p.getValue()));
//start sysout forwarding to slf4j
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J(LogLevel.INFO, LogLevel.ERROR);
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context);
context.reset(); // overwrite default configuration
//put properties into the context
properties.stream().filter(p -> isNotEmpty(p.getValue()))
.forEach(p -> context.putProperty(p.getKey(), p.getValue()));
//determine the config file
String configFilePath = getConfigFileFromClasspath();
if (configFilePath == null) {
configFilePath = getConfigFile();
}
if (configFilePath == null) {
throw new LogConfigurationException("Log configuration file '" + LOG_CONFIG_FILE_NAME + "' not found! Please ensure that your config folder or your classpath contains the file.");
}
try {
jc.doConfigure(configFilePath);
} catch (JoranException e) {
throw new LogConfigurationException("unable to run the LoggerIntializer, pleae check your config!", e);
}
logger.info("set logback configuration file '{}'", configFilePath);
// Jersey uses java.util.logging - bridge to slf4
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
示例9: initLogging
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; //导入依赖的package包/类
private static void initLogging()
{
final File logDir = new File(System.getProperty("user.home")); //new File("."); //getDir("log", Constants.TEST ? Context.MODE_WORLD_READABLE : MODE_PRIVATE);
final File logFile = new File(logDir, Version.logFileName);
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
filePattern.setContext(context);
filePattern.setPattern("%d{HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n");
filePattern.start();
final RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
fileAppender.setContext(context);
fileAppender.setFile(logFile.getAbsolutePath());
final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
rollingPolicy.setContext(context);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + Version.logFileNamePattern); //wowdoge
rollingPolicy.setMaxHistory(7);
rollingPolicy.start();
fileAppender.setEncoder(filePattern);
fileAppender.setRollingPolicy(rollingPolicy);
fileAppender.start();
final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
logcatTagPattern.setContext(context);
logcatTagPattern.setPattern("%logger{0}");
logcatTagPattern.start();
final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
logcatPattern.setContext(context);
logcatPattern.setPattern("[%thread] %msg%n");
logcatPattern.start();
//final LogcatAppender logcatAppender = new LogcatAppender();
//logcatAppender.setContext(context);
//logcatAppender.setTagEncoder(logcatTagPattern);
//logcatAppender.setEncoder(logcatPattern);
//logcatAppender.start();
final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
log.addAppender(fileAppender);
//log.addAppender(logcatAppender);
log.setLevel(Level.INFO);//Level.INFO);
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
System.out.println("Java.version: " + System.getProperty("java.version"));
}