Browse Source
* pr/4917: Polish contribution Remove support for Log4j Remove deprecated codepull/4632/merge
57 changed files with 54 additions and 1812 deletions
@ -1,139 +0,0 @@
@@ -1,139 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.actuate.metrics.writer; |
||||
|
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
import java.util.concurrent.ConcurrentMap; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
import com.codahale.metrics.Counter; |
||||
import com.codahale.metrics.Gauge; |
||||
import com.codahale.metrics.Histogram; |
||||
import com.codahale.metrics.Meter; |
||||
import com.codahale.metrics.MetricRegistry; |
||||
import com.codahale.metrics.Timer; |
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric; |
||||
import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices; |
||||
|
||||
/** |
||||
* A {@link MetricWriter} that send data to a Dropwizard {@link MetricRegistry} based on a |
||||
* naming convention. |
||||
* |
||||
* <ul> |
||||
* <li>Updates to {@link #increment(Delta)} with names in "meter.*" are treated as |
||||
* {@link Meter} events</li> |
||||
* <li>Other deltas are treated as simple {@link Counter} values</li> |
||||
* <li>Inputs to {@link #set(Metric)} with names in "histogram.*" are treated as |
||||
* {@link Histogram} updates</li> |
||||
* <li>Inputs to {@link #set(Metric)} with names in "timer.*" are treated as {@link Timer} |
||||
* updates</li> |
||||
* <li>Other metrics are treated as simple {@link Gauge} values (single valued |
||||
* measurements of type double)</li> |
||||
* </ul> |
||||
* |
||||
* @author Dave Syer |
||||
* @deprecated Since 1.3 in favor of {@link DropwizardMetricServices} |
||||
*/ |
||||
@Deprecated |
||||
public class DropwizardMetricWriter implements MetricWriter { |
||||
|
||||
private final MetricRegistry registry; |
||||
|
||||
private final ConcurrentMap<String, Object> gaugeLocks = new ConcurrentHashMap<String, Object>(); |
||||
|
||||
/** |
||||
* Create a new {@link DropwizardMetricWriter} instance. |
||||
* @param registry the underlying metric registry |
||||
*/ |
||||
public DropwizardMetricWriter(MetricRegistry registry) { |
||||
this.registry = registry; |
||||
} |
||||
|
||||
@Override |
||||
public void increment(Delta<?> delta) { |
||||
String name = delta.getName(); |
||||
long value = delta.getValue().longValue(); |
||||
if (name.startsWith("meter")) { |
||||
Meter meter = this.registry.meter(name); |
||||
meter.mark(value); |
||||
} |
||||
else { |
||||
Counter counter = this.registry.counter(name); |
||||
counter.inc(value); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void set(Metric<?> value) { |
||||
String name = value.getName(); |
||||
if (name.startsWith("histogram")) { |
||||
long longValue = value.getValue().longValue(); |
||||
Histogram metric = this.registry.histogram(name); |
||||
metric.update(longValue); |
||||
} |
||||
else if (name.startsWith("timer")) { |
||||
long longValue = value.getValue().longValue(); |
||||
Timer metric = this.registry.timer(name); |
||||
metric.update(longValue, TimeUnit.MILLISECONDS); |
||||
} |
||||
else { |
||||
final double gauge = value.getValue().doubleValue(); |
||||
// Ensure we synchronize to avoid another thread pre-empting this thread after
|
||||
// remove causing an error in Dropwizard Metrics
|
||||
// NOTE: Dropwizard Metrics provides no way to do this atomically
|
||||
synchronized (getGaugeLock(name)) { |
||||
this.registry.remove(name); |
||||
this.registry.register(name, new SimpleGauge(gauge)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private Object getGaugeLock(String name) { |
||||
Object lock = this.gaugeLocks.get(name); |
||||
if (lock == null) { |
||||
Object newLock = new Object(); |
||||
lock = this.gaugeLocks.putIfAbsent(name, newLock); |
||||
lock = (lock == null ? newLock : lock); |
||||
} |
||||
return lock; |
||||
} |
||||
|
||||
@Override |
||||
public void reset(String metricName) { |
||||
this.registry.remove(metricName); |
||||
} |
||||
|
||||
/** |
||||
* Simple {@link Gauge} implementation to {@literal double} value. |
||||
*/ |
||||
private final static class SimpleGauge implements Gauge<Double> { |
||||
|
||||
private final double value; |
||||
|
||||
private SimpleGauge(double value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
@Override |
||||
public Double getValue() { |
||||
return this.value; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -1,69 +0,0 @@
@@ -1,69 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.groovy.template; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URL; |
||||
|
||||
import groovy.text.markup.MarkupTemplateEngine; |
||||
import groovy.text.markup.TemplateConfiguration; |
||||
import groovy.text.markup.TemplateResolver; |
||||
|
||||
import org.springframework.context.i18n.LocaleContextHolder; |
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer; |
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver; |
||||
|
||||
/** |
||||
* A custom {@link groovy.text.markup.TemplateResolver template resolver} which resolves |
||||
* templates using the locale found in the thread locale. This resolver ignores the |
||||
* template engine configuration locale. |
||||
* |
||||
* @author Cédric Champeau |
||||
* @since 1.1.0 |
||||
* @deprecated since 1.2 in favor of Spring 4.1's {@link GroovyMarkupViewResolver} and |
||||
* {@link GroovyMarkupConfigurer}. |
||||
*/ |
||||
@Deprecated |
||||
public class GroovyTemplateResolver implements TemplateResolver { |
||||
|
||||
private ClassLoader templateClassLoader; |
||||
|
||||
@Override |
||||
public void configure(final ClassLoader templateClassLoader, |
||||
final TemplateConfiguration configuration) { |
||||
this.templateClassLoader = templateClassLoader; |
||||
} |
||||
|
||||
@Override |
||||
public URL resolveTemplate(final String templatePath) throws IOException { |
||||
MarkupTemplateEngine.TemplateResource templateResource = MarkupTemplateEngine.TemplateResource |
||||
.parse(templatePath); |
||||
URL resource = this.templateClassLoader.getResource(templateResource |
||||
.withLocale(LocaleContextHolder.getLocale().toString().replace("-", "_")) |
||||
.toString()); |
||||
if (resource == null) { |
||||
// no resource found with the default locale, try without any locale
|
||||
resource = this.templateClassLoader |
||||
.getResource(templateResource.withLocale(null).toString()); |
||||
} |
||||
if (resource == null) { |
||||
throw new IOException("Unable to load template:" + templatePath); |
||||
} |
||||
return resource; |
||||
} |
||||
|
||||
} |
||||
@ -1,182 +0,0 @@
@@ -1,182 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.orm.jpa; |
||||
|
||||
import java.util.Map; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.springframework.orm.jpa.JpaVendorAdapter; |
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
||||
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; |
||||
|
||||
/** |
||||
* Convenient builder for JPA EntityManagerFactory instances. Collects common |
||||
* configuration when constructed and then allows you to create one or more |
||||
* {@link LocalContainerEntityManagerFactoryBean} through a fluent builder pattern. The |
||||
* most common options are covered in the builder, but you can always manipulate the |
||||
* product of the builder if you need more control, before returning it from a |
||||
* {@code @Bean} definition. |
||||
* |
||||
* @author Dave Syer |
||||
* @since 1.1.0 |
||||
* @deprecated since 1.3.0 in favor of |
||||
* {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} |
||||
*/ |
||||
@Deprecated |
||||
public class EntityManagerFactoryBuilder { |
||||
|
||||
private final Delegate delegate; |
||||
|
||||
/** |
||||
* Create a new instance passing in the common pieces that will be shared if multiple |
||||
* EntityManagerFactory instances are created. |
||||
* @param jpaVendorAdapter a vendor adapter |
||||
* @param properties common configuration options, including generic map for JPA |
||||
* vendor properties |
||||
* @param persistenceUnitManager optional source of persistence unit information (can |
||||
* be null) |
||||
*/ |
||||
public EntityManagerFactoryBuilder(JpaVendorAdapter jpaVendorAdapter, |
||||
JpaProperties properties, PersistenceUnitManager persistenceUnitManager) { |
||||
this.delegate = new Delegate(jpaVendorAdapter, properties.getProperties(), |
||||
persistenceUnitManager); |
||||
} |
||||
|
||||
public Builder dataSource(DataSource dataSource) { |
||||
return new Builder(this.delegate.dataSource(dataSource)); |
||||
} |
||||
|
||||
/** |
||||
* An optional callback for new entity manager factory beans. |
||||
* @param callback the entity manager factory bean callback |
||||
*/ |
||||
public void setCallback(final EntityManagerFactoryBeanCallback callback) { |
||||
this.delegate.setCallback( |
||||
new org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.EntityManagerFactoryBeanCallback() { |
||||
|
||||
@Override |
||||
public void execute(LocalContainerEntityManagerFactoryBean factory) { |
||||
callback.execute(factory); |
||||
} |
||||
|
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* A fluent builder for a LocalContainerEntityManagerFactoryBean. |
||||
* @deprecated since 1.3.0 in favor of |
||||
* {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} |
||||
*/ |
||||
@Deprecated |
||||
public final class Builder { |
||||
|
||||
private final org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.Builder delegate; |
||||
|
||||
private Builder( |
||||
org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder.Builder delegate) { |
||||
this.delegate = delegate; |
||||
} |
||||
|
||||
/** |
||||
* The names of packages to scan for {@code @Entity} annotations. |
||||
* @param packagesToScan packages to scan |
||||
* @return the builder for fluent usage |
||||
*/ |
||||
public Builder packages(String... packagesToScan) { |
||||
this.delegate.packages(packagesToScan); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* The classes whose packages should be scanned for {@code @Entity} annotations. |
||||
* @param basePackageClasses the classes to use |
||||
* @return the builder for fluent usage |
||||
*/ |
||||
public Builder packages(Class<?>... basePackageClasses) { |
||||
this.delegate.packages(basePackageClasses); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* The name of the persistence unit. If only building one EntityManagerFactory you |
||||
* can omit this, but if there are more than one in the same application you |
||||
* should give them distinct names. |
||||
* @param persistenceUnit the name of the persistence unit |
||||
* @return the builder for fluent usage |
||||
*/ |
||||
public Builder persistenceUnit(String persistenceUnit) { |
||||
this.delegate.persistenceUnit(persistenceUnit); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Generic properties for standard JPA or vendor-specific configuration. These |
||||
* properties override any values provided in the {@link JpaProperties} used to |
||||
* create the builder. |
||||
* @param properties the properties to use |
||||
* @return the builder for fluent usage |
||||
*/ |
||||
public Builder properties(Map<String, ?> properties) { |
||||
this.delegate.properties(properties); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Configure if using a JTA {@link DataSource}, i.e. if |
||||
* {@link LocalContainerEntityManagerFactoryBean#setDataSource(DataSource) |
||||
* setDataSource} or |
||||
* {@link LocalContainerEntityManagerFactoryBean#setJtaDataSource(DataSource) |
||||
* setJtaDataSource} should be called on the |
||||
* {@link LocalContainerEntityManagerFactoryBean}. |
||||
* @param jta if the data source is JTA |
||||
* @return the builder for fluent usage |
||||
*/ |
||||
public Builder jta(boolean jta) { |
||||
this.delegate.jta(jta); |
||||
return this; |
||||
} |
||||
|
||||
public LocalContainerEntityManagerFactoryBean build() { |
||||
return this.delegate.build(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* A callback for new entity manager factory beans created by a Builder. |
||||
* @deprecated since 1.3.0 in favor of |
||||
* {@link org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder} |
||||
*/ |
||||
@Deprecated |
||||
public interface EntityManagerFactoryBeanCallback { |
||||
|
||||
void execute(LocalContainerEntityManagerFactoryBean factory); |
||||
|
||||
} |
||||
|
||||
private static class Delegate |
||||
extends org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder { |
||||
|
||||
Delegate(JpaVendorAdapter jpaVendorAdapter, Map<String, ?> jpaProperties, |
||||
PersistenceUnitManager persistenceUnitManager) { |
||||
super(jpaVendorAdapter, jpaProperties, persistenceUnitManager); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.orm.jpa; |
||||
|
||||
import java.util.Collections; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; |
||||
|
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertTrue; |
||||
import static org.mockito.Mockito.mock; |
||||
|
||||
/** |
||||
* Tests for {@link EntityManagerFactoryBuilder}. |
||||
* |
||||
* @author Dave Syer |
||||
*/ |
||||
@Deprecated |
||||
public class EntityManagerFactoryBuilderTests { |
||||
|
||||
private JpaProperties properties = new JpaProperties(); |
||||
|
||||
private DataSource dataSource1 = mock(DataSource.class); |
||||
|
||||
private DataSource dataSource2 = mock(DataSource.class); |
||||
|
||||
@Test |
||||
public void entityManagerFactoryPropertiesNotOverwritingDefaults() { |
||||
EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder( |
||||
new HibernateJpaVendorAdapter(), this.properties, null); |
||||
LocalContainerEntityManagerFactoryBean result1 = factory |
||||
.dataSource(this.dataSource1) |
||||
.properties(Collections.singletonMap("foo", "spam")).build(); |
||||
assertFalse(result1.getJpaPropertyMap().isEmpty()); |
||||
assertTrue(this.properties.getProperties().isEmpty()); |
||||
} |
||||
|
||||
@Test |
||||
public void multipleEntityManagerFactoriesDoNotOverwriteEachOther() { |
||||
EntityManagerFactoryBuilder factory = new EntityManagerFactoryBuilder( |
||||
new HibernateJpaVendorAdapter(), this.properties, null); |
||||
LocalContainerEntityManagerFactoryBean result1 = factory |
||||
.dataSource(this.dataSource1) |
||||
.properties(Collections.singletonMap("foo", "spam")).build(); |
||||
assertFalse(result1.getJpaPropertyMap().isEmpty()); |
||||
LocalContainerEntityManagerFactoryBean result2 = factory |
||||
.dataSource(this.dataSource2).build(); |
||||
assertTrue(result2.getJpaPropertyMap().isEmpty()); |
||||
} |
||||
|
||||
} |
||||
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<!-- Your own application should inherit from spring-boot-starter-parent --> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-samples</artifactId> |
||||
<version>1.4.0.BUILD-SNAPSHOT</version> |
||||
</parent> |
||||
<artifactId>spring-boot-sample-actuator-log4j</artifactId> |
||||
<name>Spring Boot Actuator Log4j Sample</name> |
||||
<description>Spring Boot Actuator Log4j Sample</description> |
||||
<url>http://projects.spring.io/spring-boot/</url> |
||||
<organization> |
||||
<name>Pivotal Software, Inc.</name> |
||||
<url>http://www.spring.io</url> |
||||
</organization> |
||||
<properties> |
||||
<main.basedir>${basedir}/../..</main.basedir> |
||||
</properties> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-actuator</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-logging</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-log4j</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-logging</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
</dependencies> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sample.actuator.log4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
public class HelloWorldService { |
||||
|
||||
@Autowired |
||||
private ServiceProperties configuration; |
||||
|
||||
public String getHelloMessage() { |
||||
return "Hello " + this.configuration.getName(); |
||||
} |
||||
|
||||
} |
||||
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sample.actuator.log4j; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
@SpringBootApplication |
||||
public class SampleActuatorLog4JApplication { |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
SpringApplication.run(SampleActuatorLog4JApplication.class, args); |
||||
} |
||||
|
||||
} |
||||
@ -1,46 +0,0 @@
@@ -1,46 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sample.actuator.log4j; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
@Controller |
||||
public class SampleController { |
||||
|
||||
@Autowired |
||||
private HelloWorldService helloWorldService; |
||||
|
||||
@RequestMapping("/") |
||||
@ResponseBody |
||||
public Map<String, String> helloWorld() { |
||||
return Collections.singletonMap("message", |
||||
this.helloWorldService.getHelloMessage()); |
||||
} |
||||
|
||||
@RequestMapping("/foo") |
||||
@ResponseBody |
||||
public String foo() { |
||||
throw new IllegalArgumentException("Server error"); |
||||
} |
||||
|
||||
} |
||||
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2014 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sample.actuator.log4j; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) |
||||
@Component |
||||
public class ServiceProperties { |
||||
|
||||
private String name = "World"; |
||||
|
||||
public String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
} |
||||
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
#logging.file: /tmp/logs/app.log |
||||
#server.port: 8080 |
||||
#management.port: 8080 |
||||
management.address: 127.0.0.1 |
||||
endpoints.shutdown.enabled: true |
||||
server.tomcat.basedir: target/tomcat |
||||
server.tomcat.access_log_pattern: %h %t "%r" %s %b |
||||
security.require_ssl: false |
||||
service.name: Phil |
||||
shell.ssh.enabled: true |
||||
shell.ssh.port: 2222 |
||||
#shell.telnet.enabled: false |
||||
#shell.telnet.port: 1111 |
||||
shell.auth: spring |
||||
#shell.auth: key |
||||
#shell.auth.key.path: ${user.home}/test/id_rsa.pub.pem |
||||
#shell.auth: simple |
||||
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
log4j.rootCategory=INFO, CONSOLE |
||||
|
||||
PID=???? |
||||
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] log4j%X{context} - ${PID} %5p [%t] --- %c{1}: %m%n |
||||
|
||||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout. |
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} |
||||
|
||||
log4j.category.org.hibernate.validator.internal.util.Version=WARN |
||||
log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN |
||||
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN |
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR |
||||
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2014 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sample.actuator.log4j; |
||||
|
||||
import java.util.Map; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.boot.test.SpringApplicationConfiguration; |
||||
import org.springframework.boot.test.TestRestTemplate; |
||||
import org.springframework.boot.test.WebIntegrationTest; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.test.annotation.DirtiesContext; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
|
||||
/** |
||||
* Basic integration tests for service demo application. |
||||
* |
||||
* @author Dave Syer |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@SpringApplicationConfiguration(SampleActuatorLog4JApplication.class) |
||||
@WebIntegrationTest(randomPort = true) |
||||
@DirtiesContext |
||||
public class SampleActuatorApplicationTests { |
||||
|
||||
@Value("${local.server.port}") |
||||
private int port; |
||||
|
||||
@Test |
||||
public void testHome() throws Exception { |
||||
@SuppressWarnings("rawtypes") |
||||
ResponseEntity<Map> entity = new TestRestTemplate() |
||||
.getForEntity("http://localhost:" + this.port, Map.class); |
||||
assertEquals(HttpStatus.OK, entity.getStatusCode()); |
||||
@SuppressWarnings("unchecked") |
||||
Map<String, Object> body = entity.getBody(); |
||||
assertEquals("Hello Phil", body.get("message")); |
||||
} |
||||
|
||||
@Test |
||||
public void testHealth() throws Exception { |
||||
@SuppressWarnings("rawtypes") |
||||
ResponseEntity<Map> entity = new TestRestTemplate() |
||||
.getForEntity("http://localhost:" + this.port + "/health", Map.class); |
||||
assertEquals(HttpStatus.OK, entity.getStatusCode()); |
||||
@SuppressWarnings("unchecked") |
||||
Map<String, Object> body = entity.getBody(); |
||||
assertNotNull(body.get("diskSpace")); |
||||
} |
||||
|
||||
} |
||||
@ -1,7 +0,0 @@
@@ -1,7 +0,0 @@
|
||||
log4j.rootCategory=INFO, stdout |
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n |
||||
|
||||
log4j.category.org.springframework.web=DEBUG |
||||
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starters</artifactId> |
||||
<version>1.4.0.BUILD-SNAPSHOT</version> |
||||
</parent> |
||||
<artifactId>spring-boot-starter-log4j</artifactId> |
||||
<name>Spring Boot Log4J Starter</name> |
||||
<description>Spring Boot Log4J Starter</description> |
||||
<url>http://projects.spring.io/spring-boot/</url> |
||||
<organization> |
||||
<name>Pivotal Software, Inc.</name> |
||||
<url>http://www.spring.io</url> |
||||
</organization> |
||||
<properties> |
||||
<main.basedir>${basedir}/../..</main.basedir> |
||||
</properties> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>jcl-over-slf4j</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>jul-to-slf4j</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-log4j12</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>log4j</groupId> |
||||
<artifactId>log4j</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
provides: log4j,slf4j-log4j12 |
||||
@ -1,78 +0,0 @@
@@ -1,78 +0,0 @@
|
||||
/* |
||||
* Copyright 2010-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.cloudfoundry; |
||||
|
||||
import org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor; |
||||
import org.springframework.boot.env.EnvironmentPostProcessor; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
/** |
||||
* An {@link EnvironmentPostProcessor} that knows where to find VCAP (a.k.a. Cloud |
||||
* Foundry) meta data in the existing environment. It parses out the VCAP_APPLICATION and |
||||
* VCAP_SERVICES meta data and dumps it in a form that is easily consumed by |
||||
* {@link Environment} users. If the app is running in Cloud Foundry then both meta data |
||||
* items are JSON objects encoded in OS environment variables. VCAP_APPLICATION is a |
||||
* shallow hash with basic information about the application (name, instance id, instance |
||||
* index, etc.), and VCAP_SERVICES is a hash of lists where the keys are service labels |
||||
* and the values are lists of hashes of service instance meta data. Examples are: |
||||
* |
||||
* <pre class="code"> |
||||
* VCAP_APPLICATION: {"instance_id":"2ce0ac627a6c8e47e936d829a3a47b5b","instance_index":0, |
||||
* "version":"0138c4a6-2a73-416b-aca0-572c09f7ca53","name":"foo", |
||||
* "uris":["foo.cfapps.io"], ...} |
||||
* VCAP_SERVICES: {"rds-mysql-1.0":[{"name":"mysql","label":"rds-mysql-1.0","plan":"10mb", |
||||
* "credentials":{"name":"d04fb13d27d964c62b267bbba1cffb9da","hostname":"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com", |
||||
* "host":"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com","port":3306,"user":"urpRuqTf8Cpe6", |
||||
* "username":"urpRuqTf8Cpe6","password":"pxLsGVpsC9A5S"} |
||||
* }]} |
||||
* </pre> |
||||
* |
||||
* These objects are flattened into properties. The VCAP_APPLICATION object goes straight |
||||
* to {@code vcap.application.*} in a fairly obvious way, and the VCAP_SERVICES object is |
||||
* unwrapped so that it is a hash of objects with key equal to the service instance name |
||||
* (e.g. "mysql" in the example above), and value equal to that instances properties, and |
||||
* then flattened in the same way. E.g. |
||||
* |
||||
* <pre class="code"> |
||||
* vcap.application.instance_id: 2ce0ac627a6c8e47e936d829a3a47b5b |
||||
* vcap.application.version: 0138c4a6-2a73-416b-aca0-572c09f7ca53 |
||||
* vcap.application.name: foo |
||||
* vcap.application.uris[0]: foo.cfapps.io |
||||
* |
||||
* vcap.services.mysql.name: mysql |
||||
* vcap.services.mysql.label: rds-mysql-1.0 |
||||
* vcap.services.mysql.credentials.name: d04fb13d27d964c62b267bbba1cffb9da |
||||
* vcap.services.mysql.credentials.port: 3306 |
||||
* vcap.services.mysql.credentials.host: mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com |
||||
* vcap.services.mysql.credentials.username: urpRuqTf8Cpe6 |
||||
* vcap.services.mysql.credentials.password: pxLsGVpsC9A5S |
||||
* ... |
||||
* </pre> |
||||
* |
||||
* N.B. this initializer is mainly intended for informational use (the application and |
||||
* instance ids are particularly useful). For service binding you might find that Spring |
||||
* Cloud is more convenient and more robust against potential changes in Cloud Foundry. |
||||
* |
||||
* @author Dave Syer |
||||
* @author Andy Wilkinson |
||||
* @deprecated since 1.3.0 in favor of CloudFoundryVcapEnvironmentPostProcessor |
||||
*/ |
||||
@Deprecated |
||||
public class VcapEnvironmentPostProcessor |
||||
extends CloudFoundryVcapEnvironmentPostProcessor { |
||||
|
||||
} |
||||
@ -1,134 +0,0 @@
@@ -1,134 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.logging.log4j; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.apache.log4j.Level; |
||||
import org.apache.log4j.LogManager; |
||||
import org.apache.log4j.Logger; |
||||
|
||||
import org.springframework.boot.logging.LogFile; |
||||
import org.springframework.boot.logging.LogLevel; |
||||
import org.springframework.boot.logging.LoggingInitializationContext; |
||||
import org.springframework.boot.logging.LoggingSystem; |
||||
import org.springframework.boot.logging.Slf4JLoggingSystem; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.Log4jConfigurer; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* {@link LoggingSystem} for <a href="http://logging.apache.org/log4j/1.2">Log4j</a>. |
||||
* |
||||
* @author Phillip Webb |
||||
* @author Dave Syer |
||||
* @author Andy Wilkinson |
||||
* @deprecated in Spring Boot 1.3 in favor of Apache Log4j 2 (following Apache's EOL |
||||
* declaration for log4j 1.x) |
||||
*/ |
||||
@Deprecated |
||||
public class Log4JLoggingSystem extends Slf4JLoggingSystem { |
||||
|
||||
private static final Map<LogLevel, Level> LEVELS; |
||||
|
||||
static { |
||||
Map<LogLevel, Level> levels = new HashMap<LogLevel, Level>(); |
||||
levels.put(LogLevel.TRACE, Level.TRACE); |
||||
levels.put(LogLevel.DEBUG, Level.DEBUG); |
||||
levels.put(LogLevel.INFO, Level.INFO); |
||||
levels.put(LogLevel.WARN, Level.WARN); |
||||
levels.put(LogLevel.ERROR, Level.ERROR); |
||||
levels.put(LogLevel.FATAL, Level.FATAL); |
||||
levels.put(LogLevel.OFF, Level.OFF); |
||||
LEVELS = Collections.unmodifiableMap(levels); |
||||
} |
||||
|
||||
public Log4JLoggingSystem(ClassLoader classLoader) { |
||||
super(classLoader); |
||||
} |
||||
|
||||
@Override |
||||
protected String[] getStandardConfigLocations() { |
||||
return new String[] { "log4j.xml", "log4j.properties" }; |
||||
} |
||||
|
||||
@Override |
||||
public void beforeInitialize() { |
||||
super.beforeInitialize(); |
||||
LogManager.getRootLogger().setLevel(Level.FATAL); |
||||
} |
||||
|
||||
@Override |
||||
protected void loadDefaults(LoggingInitializationContext initializationContext, |
||||
LogFile logFile) { |
||||
if (logFile != null) { |
||||
loadConfiguration(getPackagedConfigFile("log4j-file.properties"), logFile); |
||||
} |
||||
else { |
||||
loadConfiguration(getPackagedConfigFile("log4j.properties"), logFile); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected void loadConfiguration(LoggingInitializationContext initializationContext, |
||||
String location, LogFile logFile) { |
||||
loadConfiguration(location, logFile); |
||||
} |
||||
|
||||
protected void loadConfiguration(String location, LogFile logFile) { |
||||
Assert.notNull(location, "Location must not be null"); |
||||
if (logFile != null) { |
||||
logFile.applyToSystemProperties(); |
||||
} |
||||
try { |
||||
Log4jConfigurer.initLogging(location); |
||||
} |
||||
catch (Exception ex) { |
||||
throw new IllegalStateException( |
||||
"Could not initialize Log4J logging from " + location, ex); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected void reinitialize(LoggingInitializationContext initializationContext) { |
||||
loadConfiguration(getSelfInitializationConfig(), null); |
||||
} |
||||
|
||||
@Override |
||||
public void setLogLevel(String loggerName, LogLevel level) { |
||||
Logger logger = (StringUtils.hasLength(loggerName) |
||||
? LogManager.getLogger(loggerName) : LogManager.getRootLogger()); |
||||
logger.setLevel(LEVELS.get(level)); |
||||
} |
||||
|
||||
@Override |
||||
public Runnable getShutdownHandler() { |
||||
return new ShutdownHandler(); |
||||
} |
||||
|
||||
private static final class ShutdownHandler implements Runnable { |
||||
|
||||
@Override |
||||
public void run() { |
||||
LogManager.shutdown(); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2014 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
/** |
||||
* Support for the Log4j logging library. |
||||
*/ |
||||
package org.springframework.boot.logging.log4j; |
||||
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.test; |
||||
|
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainer; |
||||
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; |
||||
import org.springframework.context.ApplicationContextInitializer; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
/** |
||||
* {@link ApplicationContextInitializer} that sets {@link Environment} properties for the |
||||
* ports that {@link EmbeddedServletContainer} servers are actually listening on. The |
||||
* property {@literal "local.server.port"} can be injected directly into tests using |
||||
* {@link Value @Value} or obtained via the {@link Environment}. |
||||
* <p> |
||||
* If the {@link EmbeddedWebApplicationContext} has a |
||||
* {@link EmbeddedWebApplicationContext#setNamespace(String) namespace} set, it will be |
||||
* used to construct the property name. For example, the "management" actuator context |
||||
* will have the property name {@literal "local.management.port"}. |
||||
* <p> |
||||
* Properties are automatically propagated up to any parent context. |
||||
* |
||||
* @author Dave Syer |
||||
* @author Phillip Webb |
||||
* @deprecated since 1.3 in favor of |
||||
* org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer |
||||
*/ |
||||
@Deprecated |
||||
public class ServerPortInfoApplicationContextInitializer extends |
||||
org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer { |
||||
|
||||
} |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
log4j.rootCategory=INFO, CONSOLE, FILE |
||||
|
||||
PID=???? |
||||
LOG_PATH=${java.io.tmpdir} |
||||
LOG_FILE=${LOG_PATH}/spring.log |
||||
LOG_LEVEL_PATTERN=%5p |
||||
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${PID} ${LOG_LEVEL_PATTERN} [%t] --- %c{1}: %m%n |
||||
|
||||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout. |
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} |
||||
|
||||
log4j.appender.FILE=org.apache.log4j.RollingFileAppender |
||||
log4j.appender.FILE.File=${LOG_FILE} |
||||
log4j.appender.FILE.MaxFileSize=10MB |
||||
log4j.appender.FILE.layout = org.apache.log4j.PatternLayout |
||||
log4j.appender.FILE.layout.ConversionPattern=${LOG_PATTERN} |
||||
|
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR |
||||
log4j.category.org.apache.catalina.util.LifecycleBase=ERROR |
||||
log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN |
||||
log4j.category.org.apache.sshd.common.util.SecurityUtils |
||||
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN |
||||
log4j.category.org.crsh.plugin=WARN |
||||
log4j.category.org.crsh.ssh=WARN |
||||
log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR |
||||
log4j.category.org.hibernate.validator.internal.util.Version=WARN |
||||
log4j.category.org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration=WARN |
||||
log4j.category.org.springframework.boot.actuate.endpoint.jmx=WARN |
||||
log4j.category.org.thymeleaf=WARN |
||||
|
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
log4j.rootCategory=INFO, CONSOLE |
||||
|
||||
PID=???? |
||||
LOG_LEVEL_PATTERN=%5p |
||||
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${PID} ${LOG_LEVEL_PATTERN} [%t] --- %c{1}: %m%n |
||||
|
||||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout. |
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} |
||||
|
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR |
||||
log4j.category.org.apache.catalina.util.LifecycleBase=ERROR |
||||
log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN |
||||
log4j.category.org.apache.sshd.common.util.SecurityUtils |
||||
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN |
||||
log4j.category.org.crsh.plugin=WARN |
||||
log4j.category.org.crsh.ssh=WARN |
||||
log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR |
||||
log4j.category.org.hibernate.validator.internal.util.Version=WARN |
||||
log4j.category.org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration=WARN |
||||
log4j.category.org.springframework.boot.actuate.endpoint.jmx=WARN |
||||
log4j.category.org.thymeleaf=WARN |
||||
@ -1,154 +0,0 @@
@@ -1,154 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2015 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.logging.log4j; |
||||
|
||||
import java.io.File; |
||||
import java.util.logging.Handler; |
||||
import java.util.logging.LogManager; |
||||
|
||||
import org.apache.commons.logging.impl.Log4JLogger; |
||||
import org.junit.After; |
||||
import org.junit.Before; |
||||
import org.junit.Ignore; |
||||
import org.junit.Rule; |
||||
import org.junit.Test; |
||||
import org.slf4j.bridge.SLF4JBridgeHandler; |
||||
|
||||
import org.springframework.boot.logging.AbstractLoggingSystemTests; |
||||
import org.springframework.boot.logging.LogLevel; |
||||
import org.springframework.boot.test.OutputCapture; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import static org.hamcrest.Matchers.equalTo; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertThat; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
/** |
||||
* Tests for {@link Log4JLoggingSystem}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
@SuppressWarnings("deprecation") |
||||
public class Log4JLoggingSystemTests extends AbstractLoggingSystemTests { |
||||
|
||||
@Rule |
||||
public OutputCapture output = new OutputCapture(); |
||||
|
||||
private final Log4JLoggingSystem loggingSystem = new Log4JLoggingSystem( |
||||
getClass().getClassLoader()); |
||||
|
||||
private Log4JLogger logger; |
||||
|
||||
@Before |
||||
public void setup() { |
||||
this.logger = new Log4JLogger(getClass().getName()); |
||||
} |
||||
|
||||
@Override |
||||
@After |
||||
public void clear() { |
||||
this.loggingSystem.cleanUp(); |
||||
} |
||||
|
||||
@Test |
||||
public void noFile() throws Exception { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.logger.info("Hidden"); |
||||
this.loggingSystem.initialize(null, null, null); |
||||
this.logger.info("Hello world"); |
||||
String output = this.output.toString().trim(); |
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world")); |
||||
assertFalse("Output not hidden:\n" + output, output.contains("Hidden")); |
||||
assertFalse(new File(tmpDir() + "/spring.log").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void withFile() throws Exception { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.logger.info("Hidden"); |
||||
this.loggingSystem.initialize(null, null, getLogFile(null, tmpDir())); |
||||
this.logger.info("Hello world"); |
||||
String output = this.output.toString().trim(); |
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world")); |
||||
assertFalse("Output not hidden:\n" + output, output.contains("Hidden")); |
||||
assertTrue(new File(tmpDir() + "/spring.log").exists()); |
||||
} |
||||
|
||||
@Test |
||||
public void testNonDefaultConfigLocation() throws Exception { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.loggingSystem.initialize(null, "classpath:log4j-nondefault.properties", |
||||
getLogFile(null, tmpDir())); |
||||
this.logger.info("Hello world"); |
||||
String output = this.output.toString().trim(); |
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world")); |
||||
assertTrue("Wrong output:\n" + output, output.contains(tmpDir() + "/spring.log")); |
||||
assertFalse(new File(tmpDir() + "/tmp.log").exists()); |
||||
} |
||||
|
||||
@Test(expected = IllegalStateException.class) |
||||
public void testNonexistentConfigLocation() throws Exception { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.loggingSystem.initialize(null, "classpath:log4j-nonexistent.xml", null); |
||||
} |
||||
|
||||
@Test |
||||
public void setLevel() throws Exception { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.loggingSystem.initialize(null, null, null); |
||||
this.logger.debug("Hello"); |
||||
this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG); |
||||
this.logger.debug("Hello"); |
||||
assertThat(StringUtils.countOccurrencesOf(this.output.toString(), "Hello"), |
||||
equalTo(1)); |
||||
} |
||||
|
||||
@Test |
||||
@Ignore("Fails on Bamboo") |
||||
public void loggingThatUsesJulIsCaptured() { |
||||
this.loggingSystem.beforeInitialize(); |
||||
this.loggingSystem.initialize(null, null, null); |
||||
java.util.logging.Logger julLogger = java.util.logging.Logger |
||||
.getLogger(getClass().getName()); |
||||
julLogger.severe("Hello world"); |
||||
String output = this.output.toString().trim(); |
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world")); |
||||
} |
||||
|
||||
@Test |
||||
public void bridgeHandlerLifecycle() { |
||||
assertFalse(bridgeHandlerInstalled()); |
||||
this.loggingSystem.beforeInitialize(); |
||||
assertTrue(bridgeHandlerInstalled()); |
||||
this.loggingSystem.cleanUp(); |
||||
assertFalse(bridgeHandlerInstalled()); |
||||
} |
||||
|
||||
private boolean bridgeHandlerInstalled() { |
||||
java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger(""); |
||||
Handler[] handlers = rootLogger.getHandlers(); |
||||
for (Handler handler : handlers) { |
||||
if (handler instanceof SLF4JBridgeHandler) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -1,10 +0,0 @@
@@ -1,10 +0,0 @@
|
||||
log4j.reset=true |
||||
log4j.rootCategory=INFO, CONSOLE |
||||
|
||||
PID=???? |
||||
LOG_PATTERN=${LOG_FILE} %d{yyyy-MM-dd HH:mm:ss.SSS}] service%X{context} - ${PID} %5p [%t] --- %c{1}: %m%n |
||||
|
||||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout. |
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} |
||||
Loading…
Reference in new issue