温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Springboot怎么与graylog结合使用

发布时间:2020-12-10 14:10:40 来源:亿速云 阅读:377 作者:Leah 栏目:开发技术

Springboot怎么与graylog结合使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

graylog配置

Springboot怎么与graylog结合使用

Springboot怎么与graylog结合使用

springboot配置

依赖

compile group: 'de.siegmar', name: 'logback-gelf',

version: '2.0.0'

logback.xml

<configuration>
  <!-- 配置控制台的输出日志 -->
  <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <!-- 定义日志输出的格式 -->
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>
          %d - [%thread] %-5level %logger{35} - [%line] - %msg%n
        </pattern>
      </layout>
    </encoder>
  </appender>

  <appender name="GELF" class="de.siegmar.logbackgelf.GelfUdpAppender">
    <!-- Graylog服务的地址 -->
    <graylogHost>172.23.62.248</graylogHost>
    <!-- UDP Input端口 -->
    <graylogPort>12201</graylogPort>
    <!-- 最大GELF数据块大小(单位:字节),508为建议最小值,最大值为65467 -->
    <maxChunkSize>508</maxChunkSize>
    <!-- 是否使用压缩 -->
    <useCompression>true</useCompression>
    <encoder class="de.siegmar.logbackgelf.GelfEncoder">
      <!-- 是否发送原生的日志信息 -->
      <includeRawMessage>false</includeRawMessage>
      <includeMarker>true</includeMarker>
      <includeMdcData>true</includeMdcData>
      <includeCallerData>false</includeCallerData>
      <includeRootCauseData>false</includeRootCauseData>
      <!-- 是否发送日志级别的名称,否则默认以数字代表日志级别 -->
      <includeLevelName>true</includeLevelName>
      <shortPatternLayout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%m%nopex</pattern>
      </shortPatternLayout>
      <fullPatternLayout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%d - [%thread] %-5level %logger{35} - %msg%n</pattern>
      </fullPatternLayout>
      <!-- 配置应用名称(服务名称),通过staticField标签可以自定义一些固定的日志字段 -->
      <staticField>app_name:zzl-test</staticField>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="GELF" />
    <appender-ref ref="consoleLog" />
  </root>
</configuration>

写一个测试方法

Springboot怎么与graylog结合使用

graylog搜索结果

Springboot怎么与graylog结合使用

看完上述内容,你们掌握Springboot怎么与graylog结合使用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI