private void logWithTracker()

in services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/helpers/LoggingHelper.java [243:285]


    private void logWithTracker(ApplicationLog log, String tracker, String msg, Level level, Object [] extraAttributes) {

        // Enable JSON logging with Logback and SLF4J by enabling the Logstash JSON Encoder in your logback.xml configuration.

        String payload = String.format("%s | %s | %s | %s | %s",
                applicationName,
                log,
                loggerName,
                tracker,
                msg
        );

        String runId;
        try{
            runId = TrackingHelper.parseRunIdAsPrefix(tracker);
        }catch (Exception e){
            // so that it never appears in max(run_id) queries
            runId = "0000000000000-z";
        }

        Object [] globalAttributes = new Object[]{
                kv("global_app", this.applicationName),
                kv("global_logger_name", this.loggerName),
                kv("global_app_log", log),
                kv("global_tracker", tracker),
                kv("global_run_id", runId),
                kv("global_msg", msg),
                kv("severity", level.toString()),

                // Group all log entries with the same tracker in CLoud Logging iew
                kv("logging.googleapis.com/trace",
                        String.format("projects/%s/traces/%s", projectId, tracker))
        };

        // setting the "severity" KV will override the logger.<severity>
        logger.info(
                payload,
                Stream.concat(
                        Arrays.stream(globalAttributes),
                        Arrays.stream(extraAttributes)
                ).toArray()
        );
    }