snowdrop / java-buildpack-client

A simple buildpack (https://buildpacks.io/) platform implementation as a library for java..
Apache License 2.0
13 stars 7 forks source link

How can I get logs ? #13

Closed fatiiates closed 2 years ago

fatiiates commented 2 years ago

Hi,

I need to show the outputs to users on a different platform instead of the console, so I want to access the logs written to the console. Can you help me ?

fatiiates commented 2 years ago

I didn't get the logs. It is probably generally preferable to be directed rather than taken.

So, you have defined an interface named LogReader. I also created the following class that I implemented from LogReader class.

public static class BuildpacksLogger implements LogReader {

        private PrintStream ps;

        BuildpacksLogger(){}

        BuildpacksLogger(PrintStream ps){
            this.ps = ps;
        }

        @Override
        public boolean stripAnsiColor() {
            return true;
        }

        @Override
        public void stdout(String message) {
            if (message.endsWith("\n")) {
                message = message.substring(0, message.length() - 1);
            }           
            ps.println(message);            
        }

        @Override
        public void stderr(String message) {
            if (message.endsWith("\n")) {
                message = message.substring(0, message.length() - 1);
            }
            ps.println(message);
        } 

    }

I cannot export the logs in the BuildpackBuilderImpl class at the moment. However, it was enough to get the current lifecycle logs. Thanks.