Coder Social home page Coder Social logo

Comments (4)

suraj-qlogic avatar suraj-qlogic commented on June 25, 2024 1

@jebbench ,please follow here java-logging-206 for progress/work related to your request.

from java-logging-logback.

suraj-qlogic avatar suraj-qlogic commented on June 25, 2024

@jebbench ,Thanks for filling issue.For a Kubernetes container instance set the name of the monitored resource k8s_container as resource_type in logback configuration.Can you please try below configuration.

logback.xml

<configuration>
    <appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
        <!-- Optional : filter logs at or above a level -->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <log>my-log-test</log> <!-- Optional : default java.log -->
        <resourceType>k8s_container</resourceType>
        <flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
    </appender>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="debug">
        <appender-ref ref="CLOUD"/>
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

Code:

public class TestLogger {
  private static final Logger logger = LoggerFactory.getLogger(TestLogger.class);

  public static void main(String[] args) {
    logger.info("Logging INFO");
  }
}

output:

comment_answer

from java-logging-logback.

jebbench avatar jebbench commented on June 25, 2024

@suraj-qlogic thanks for looking into this.

Adding the setting the resource type correctly sets the resource type however it doesn't fill in any of the resource labels:

resource: {
  type: "k8s_container"
  labels: {
    cluster_name: ""
    pod_name: ""
    container_name: ""
    namespace_name: ""
    location: ""
    project_id: "XXX"
   }
}

My ultimate aim is to have the logs from my Java application correctly associated to the cluster/namespace/pod/container that creates them with the correct log levels.

I can achive the correct association by simply logging to STDOUT however this doesn't correctly pick up the log levels - this library correctly sets the log levels but doesn't associate the logs with the container.

I've tried emiting logs to STDOUT in the logstash JSON format but stackdriver doesn't parse the log level.

from java-logging-logback.

suraj-qlogic avatar suraj-qlogic commented on June 25, 2024

@jebbench ,I'm closing this bug seems PR-207 was merged and this feature is available on latest version release of java logging client.
Feel free to comment back if for some reason you feel it's not sufficient.

from java-logging-logback.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.