配置Logback - logback.xml

时间:2016-06-14 06:42:14

标签: java xml logback web.xml

我在给定的tomcat中运行了许多相同的应用程序,这些应用程序都在不同的URL和web.xml文件下运行。

我想为每个logback.xml制作一个相同的%property{}。但我希望模式中包含servername或display-name。我已尝试${}<configuration scan="true" scanPeriod="30 seconds"> <!-- output changes to logging status to the console. Handy to see when your changes have been reflected. --> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <root level="warn"> <appender-ref ref="STDOUT" /> </root> <logger name="org.apache.jsp.actions.form" level="debug" /> <logger name="com.sok.runway.offline.rpmManager" level="debug" /> </configuration> 将其放入,但没有运气。

该应用程序已有12年以上的历史,它没有使用现代框架,因此返回很简单。

#include<stdio.h>
   #include<string.h>
   typedef struct emp
   {
           char name[100];
           int age;
   }ee;
   void main()
   {
           struct emp p;
           FILE *ptr;
           int i;
           char ch[100];
           ptr=fopen("ddd.txt","w+");
           if(ptr==NULL)
           {
                   printf("\n not able to open the file");
           }
           for(i=0;i<3;i++)
           {
                   printf("Enter the name and the age");
                   fgets(p.name,100,stdin);
                   fflush(stdout);
                   scanf("%d",&p.age);
                   fprintf(ptr,"%s%d",p.name,p.age);
                   fflush(stdout);
           }
fclose(ptr);
   }

1 个答案:

答案 0 :(得分:0)

您可以使用.properties文件来指定服务器和显示名称。

application-logback.properties :(或者你可能想要命名文件)

servername=production
displayname=MyDisplayName

logback config:

<configuration scan="true" scanPeriod="30 seconds">
    <property resource="application-logback.properties" /><!-- this is new -->

    <!-- output changes to logging status to the console. Handy to see when your changes have been reflected. -->
    <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder><!-- new pattern with the 2 properties -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${servername}] [${displayname}] [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="warn">
        <appender-ref ref="STDOUT" />
    </root>
    <logger name="org.apache.jsp.actions.form" level="debug" />
      <logger name="com.sok.runway.offline.rpmManager" level="debug" />
</configuration>

如何将实际的servernamedisplayname放入.properties文件中,我不知道。

相关问题