logback value from web.xml
I'm trying to take a value from spring profile set in web.xml. I've already encountered a question that solves my problem but the implementation of the solution to the problem does not seem to be working. That's are my source code:
web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>local-jboss</param-value>
</context-param>
logback.xml:
<insertFromJNDI env-entry-name="java:comp/env/spring.profiles.default" as="spring.profiles.default" />
<appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>x.x.x.x:yyyy</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
<context /> <!-- Outputs entries from logback's context -->
<version /> <!-- Logstash json format version, the @version field in the output -->
<logLevel />
<loggerName />
<pattern>
<pattern>
{
"APP": "MyApp",
"PROFILE": "${spring.profiles.default}"
}
</pattern>
</pattern>
<threadName />
<message />
<logstashMarkers /> <!-- Useful so we can add extra information for specific log lines as Markers -->
<arguments /> <!-- or through StructuredArguments -->
<stackTrace />
</providers>
</encoder>
</appender>
Does anyone know how I get the value from my web.xml and put in logback.xml?
java spring logback web.xml
add a comment |
I'm trying to take a value from spring profile set in web.xml. I've already encountered a question that solves my problem but the implementation of the solution to the problem does not seem to be working. That's are my source code:
web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>local-jboss</param-value>
</context-param>
logback.xml:
<insertFromJNDI env-entry-name="java:comp/env/spring.profiles.default" as="spring.profiles.default" />
<appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>x.x.x.x:yyyy</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
<context /> <!-- Outputs entries from logback's context -->
<version /> <!-- Logstash json format version, the @version field in the output -->
<logLevel />
<loggerName />
<pattern>
<pattern>
{
"APP": "MyApp",
"PROFILE": "${spring.profiles.default}"
}
</pattern>
</pattern>
<threadName />
<message />
<logstashMarkers /> <!-- Useful so we can add extra information for specific log lines as Markers -->
<arguments /> <!-- or through StructuredArguments -->
<stackTrace />
</providers>
</encoder>
</appender>
Does anyone know how I get the value from my web.xml and put in logback.xml?
java spring logback web.xml
add a comment |
I'm trying to take a value from spring profile set in web.xml. I've already encountered a question that solves my problem but the implementation of the solution to the problem does not seem to be working. That's are my source code:
web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>local-jboss</param-value>
</context-param>
logback.xml:
<insertFromJNDI env-entry-name="java:comp/env/spring.profiles.default" as="spring.profiles.default" />
<appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>x.x.x.x:yyyy</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
<context /> <!-- Outputs entries from logback's context -->
<version /> <!-- Logstash json format version, the @version field in the output -->
<logLevel />
<loggerName />
<pattern>
<pattern>
{
"APP": "MyApp",
"PROFILE": "${spring.profiles.default}"
}
</pattern>
</pattern>
<threadName />
<message />
<logstashMarkers /> <!-- Useful so we can add extra information for specific log lines as Markers -->
<arguments /> <!-- or through StructuredArguments -->
<stackTrace />
</providers>
</encoder>
</appender>
Does anyone know how I get the value from my web.xml and put in logback.xml?
java spring logback web.xml
I'm trying to take a value from spring profile set in web.xml. I've already encountered a question that solves my problem but the implementation of the solution to the problem does not seem to be working. That's are my source code:
web.xml:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>local-jboss</param-value>
</context-param>
logback.xml:
<insertFromJNDI env-entry-name="java:comp/env/spring.profiles.default" as="spring.profiles.default" />
<appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>x.x.x.x:yyyy</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
<context /> <!-- Outputs entries from logback's context -->
<version /> <!-- Logstash json format version, the @version field in the output -->
<logLevel />
<loggerName />
<pattern>
<pattern>
{
"APP": "MyApp",
"PROFILE": "${spring.profiles.default}"
}
</pattern>
</pattern>
<threadName />
<message />
<logstashMarkers /> <!-- Useful so we can add extra information for specific log lines as Markers -->
<arguments /> <!-- or through StructuredArguments -->
<stackTrace />
</providers>
</encoder>
</appender>
Does anyone know how I get the value from my web.xml and put in logback.xml?
java spring logback web.xml
java spring logback web.xml
asked Nov 22 '18 at 20:07
IsdenielIsdeniel
456
456
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
1st Solution :
If you are on spring 3.1+ then those context params will available as env variable and in logback you can easily refer them like below :
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
source
is the name of your key. Further Documentation.
2nd Solution :
You can use this as well where we will define context-param as spring property then refer the same in logback as 1st solution above.
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:" + servletContext.getInitParameter("test.property"));
return builder.sources(DemoApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}
Hope this helps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437477%2flogback-value-from-web-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
1st Solution :
If you are on spring 3.1+ then those context params will available as env variable and in logback you can easily refer them like below :
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
source
is the name of your key. Further Documentation.
2nd Solution :
You can use this as well where we will define context-param as spring property then refer the same in logback as 1st solution above.
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:" + servletContext.getInitParameter("test.property"));
return builder.sources(DemoApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}
Hope this helps.
add a comment |
1st Solution :
If you are on spring 3.1+ then those context params will available as env variable and in logback you can easily refer them like below :
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
source
is the name of your key. Further Documentation.
2nd Solution :
You can use this as well where we will define context-param as spring property then refer the same in logback as 1st solution above.
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:" + servletContext.getInitParameter("test.property"));
return builder.sources(DemoApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}
Hope this helps.
add a comment |
1st Solution :
If you are on spring 3.1+ then those context params will available as env variable and in logback you can easily refer them like below :
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
source
is the name of your key. Further Documentation.
2nd Solution :
You can use this as well where we will define context-param as spring property then refer the same in logback as 1st solution above.
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:" + servletContext.getInitParameter("test.property"));
return builder.sources(DemoApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}
Hope this helps.
1st Solution :
If you are on spring 3.1+ then those context params will available as env variable and in logback you can easily refer them like below :
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
source
is the name of your key. Further Documentation.
2nd Solution :
You can use this as well where we will define context-param as spring property then refer the same in logback as 1st solution above.
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:" + servletContext.getInitParameter("test.property"));
return builder.sources(DemoApp.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}
Hope this helps.
answered Nov 23 '18 at 18:25
bittubittu
347110
347110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437477%2flogback-value-from-web-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown