cloud-code-intellij icon indicating copy to clipboard operation
cloud-code-intellij copied to clipboard

As a user I want to have human readable Stackdriver logs in IntelliJ

Open Alos opened this issue 5 years ago • 10 comments

- Cloud Code for IntelliJ version: IntelliJ IDEA 2019.3.2 (Ultimate Edition) - OS: MacOS

What did you do? Used CC to develop an application on Kubernetes What did you expect to see? I expected to see human readable logs as they are streamed into IntelliJ What did you see instead? JSON formated strings show up instead.

The same happens if I stream logs using the Kubernetes Explorer

Alos avatar Jan 30 '20 23:01 Alos

@Alos Just curious - are the logs containing the unformatted json, application logs? Or are they logs from skaffold (or something else)?

etanshaul avatar Jan 31 '20 16:01 etanshaul

These are application logs exposed by Spring Cloud GCP and the following configuration for Stackdriver:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <include resource="org/springframework/cloud/gcp/logging/logback-json-appender.xml"/>

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

Alos avatar Jan 31 '20 17:01 Alos

@Alos Was the workaround given in chat (updating the logger configuration for Spring Boot) good enough or does this require further investigation?

jmah-cc avatar Jun 11 '20 16:06 jmah-cc

So far, I have not been able to configure logging to be Stackdriver friendly and human readable.

On Thu, Jun 11, 2020 at 9:37 AM Jay Mahendru [email protected] wrote:

@Alos https://github.com/Alos Was the workaround given in chat (updating the logger configuration for Spring Boot) good enough or does this require further investigation?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/cloud-code-intellij/issues/2701#issuecomment-642795908, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGG5AGEV5LLSV5OIIYLR3RWEB43ANCNFSM4KN6TZVA .

--

Sergio Felix

Software Engineer

Alos avatar Jun 11 '20 16:06 Alos

Hey @Alos . Sorry for the slow turnaround on this, but I spent some time today playing around with this to see if I can get a working configuration. I was a bit skeptical that Cloud Code is the place to solve this. I made a few assumptions about your setup though:

  • Spring Boot application using the spring-cloud-gcp-starter-logging artifact for stackdriver logging integration
  • A logback configuration that is configured to use the spring cloud logback-json-appender.xml which logs output to JSON so that it is consumable by Stackdriver:
<configuration>
  <include resource=
                         "org/springframework/cloud/gcp/logging/logback-json-appender.xml"/>
    <root level="INFO">
        <appender-ref ref="CONSOLE_JSON"/>
    </root>
<configuration>

Goal: Configure a logback appender for local dev that will output logs in a human readable way (e.g. not JSON).

Solution that worked for me: Use Spring Profiles to configure different logback appenders per environment.

In my logback-spring.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <springProfile name="dev">
        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>
                    %d{HH:mm:ss.SSS} | %5p | %logger{25} | %m%n
                </pattern>
                <charset>utf8</charset>
            </encoder>
        </appender>
        <root level="DEBUG">
            <appender-ref ref="CONSOLE"/>
        </root>
    </springProfile>
    <springProfile name="prod">
        <include resource=
                         "org/springframework/cloud/gcp/logging/logback-json-appender.xml"/>
        <root level="INFO">
            <appender-ref ref="CONSOLE_JSON"/>
        </root>
    </springProfile>
</configuration>

Notice the two profiles:

  • dev uses a standard CONSOLE appender
  • prod uses the CONSOLE_JSON appender for consumption by stackdriver

Then, to activate the dev profile, for instance, I set an environment variable: spring.profiles.active=dev.

Result: Human readable application logs, not json formatted.

Let me know if this works for you and if not where I made incorrect assumptions. Looking forward to finding a solution that works :)

etanshaul avatar Nov 23 '20 21:11 etanshaul

This is a good workaround for development workflows, where you can switch the profile. But does not solve the problem when we are inspecting troubleshooting services already running in other environments.

Alos avatar Nov 23 '20 22:11 Alos

Don't have plans to fix this as it's not a priority (and we have a partial workaround) at this time. Everyone: please upvote if you'd like to see this improvement and we'll re-visit

jmah-cc avatar Feb 26 '21 19:02 jmah-cc

Be aware that this only works for development and not for troubleshooting an app already running in the GKE cluster.

Alos avatar Feb 26 '21 19:02 Alos

Thanks @Alos on second thought I think we should keep this open. The robust solution would be to create a full featured log viewer like VSC has. I'll keep this open to track that part of the effort.

etanshaul avatar Feb 26 '21 19:02 etanshaul

I second this motion. The console log viewer is kind of slow to response for me, due to a bad internet connection. Having a full log viewer in standalone tool, like Cloud Code, would be a god gift.

PierrickPuimeanChieze avatar Nov 03 '22 08:11 PierrickPuimeanChieze