Code Monkey home page Code Monkey logo

Comments (6)

tanin47 avatar tanin47 commented on June 13, 2024

Could you elaborate on what logging module you'll remove? I am using JSON logging with openjdk-image right now. I just want to make sure I can continue to use it.

Currently, I'm writing JSON logs to /var/log/app_engine/app-test.json; it seems to work well. Thank you!

from openjdk-runtime.

gregw avatar gregw commented on June 13, 2024

@tanin47 we have removed the com.google.cloud.runtimes.logging.JsonFormatter class. Are you using this class directly?

Note that it has already been removed by #38 and this issue should have been closed. Will leave open until we determine if you are using it or not.

from openjdk-runtime.

tanin47 avatar tanin47 commented on June 13, 2024

Ok, I've got it now. And, no, I am not using that class. I'm using net.logstash.logback.encoder.LogstashEncoder. We are good. Thank you.

from openjdk-runtime.

meltsufin avatar meltsufin commented on June 13, 2024

@tanin47 Can you share your logging configuration for the benefit of others who might want to use it?

from openjdk-runtime.

tanin47 avatar tanin47 commented on June 13, 2024

Definitely! I am using JSON logging with playframework (deployed on this docker image). Here's is my logback.xml:

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/var/log/app_engine/app-play.json</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>/var/log/app_engine/rolled-app-play-%i.json</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>10</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>5MB</maxFileSize>
        </triggeringPolicy>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <includeContext>false</includeContext>
            <fieldNames>
                <thread>[ignore]</thread>
                <levelValue>[ignore]</levelValue>
                <logger>logger</logger>
                <version>[ignore]</version>
            </fieldNames>
        </encoder>
    </appender>

    <logger name="play" level="INFO" />
    <logger name="application" level="DEBUG" />

    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>
    <shutdownHook/>
</configuration>

Please note that (1) rolling logs, (2) the path of the log file, and (3) encoder are essential.

And, in build.sbt, we include the below library:

libraryDependencies ++= Seq(
  "net.logstash.logback" % "logstash-logback-encoder" % "4.0",
  "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
)

And, in the code, we can write JSON logs with extra fields as shown below:

import com.typesafe.scalalogging.{Logger => ScalaLogger}
import net.logstash.logback.marker.Markers._
import org.slf4j.Marker
import play.api.{Logger => PlayLogger}

import scala.collection.JavaConversions._
import scala.language.implicitConversions

def getLogger: ScalaLogger = {
  ScalaLogger(PlayLogger(new Throwable().getStackTrace()(2).getClassName.stripSuffix("$")).logger)
}

implicit def mapToMapEntriesAppendingMarker[K, V](m: Map[K, V]): Marker = {
  append("extras", m: java.util.Map[K, V])
}

object SomeObject {
  val logger = getLogger
  logger.info(Map("some-field" -> "some-value"), "some-message")
}

from openjdk-runtime.

meltsufin avatar meltsufin commented on June 13, 2024

@tanin47 This is great! Thanks for sharing!

from openjdk-runtime.

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.