Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPHEE: first pass at adding logging for applications #962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martyphee
Copy link

@martyphee martyphee commented Jun 17, 2022

MultiLang Daemon StdLogger call

Adding the ability for the clients to send logging messages through the normal stdout by having the KCL process new LogMessages

WIP right now

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

2022-06-17 13:31:49,176 [ShardRecordProcessor-0001] INFO  s.a.k.multilang.messages.LogMessage [NONE] - Processing record with key AN_ID_OF_A_POLICY 
2022-06-17 13:31:49,176 [multi-lang-daemon-0003] INFO  s.a.kinesis.multilang.LineReaderTask [NONE] - Starting: Reading next message from STDIN for shardId-000000000000 
2022-06-17 13:31:49,177 [ShardRecordProcessor-0001] ERROR s.a.k.multilang.messages.LogMessage [NONE] - Processing record with key AN_ID_OF_A_POLICY 

Python side maybe?

class KclLogger:
    class LogLevel(Enum):
        INFO = "info"
        DEBUG = "debug"
        ERROR = "error"
        WARN = "warn"

    def debug(self, message: str):
        self._write_action(self.LogLevel.DEBUG.value, message)

    def info(self, message: str):
        self._write_action(self.LogLevel.INFO.value, message)

    def warn(self, message: str):
        self._write_action(self.LogLevel.WARN.value, message)

    def error(self, message: str):
        self._write_action(self.LogLevel.ERROR.value, message)

    @staticmethod
    def _write_action(log_level: LogLevel, message: str):
        kclprocess.io_handler.write_action(KclLogger._create_message(log_level, message))

    @staticmethod
    def _create_message(log_level: LogLevel, message: str):
        return {
            "action": "log",
            "logLevel": log_level,
            "message": message
        }

@stair-aws stair-aws added the v2.x Issues related to the 2.x version label Feb 3, 2023
Copy link
Contributor

@brendan-p-lynch brendan-p-lynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this draft if you still would like this to be added

import software.amazon.kinesis.multilang.messages.ShardEndedMessage;
import software.amazon.kinesis.multilang.messages.ShutdownRequestedMessage;
import software.amazon.kinesis.multilang.messages.StatusMessage;
import software.amazon.kinesis.multilang.messages.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be adding wildcards for imports. This should explictly state all the things we need to import

log.info("Client logging: " + this.message);
}

public Function<String, Boolean> getLogger() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be returning only a boolean, not a Function<String, Boolean>. Also everything returns true. What is the benefit of returning a value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's returning a function

return (m) -> {
                     log.debug(m);
                     return true;
                 };

Not sure a better return type since Function requires one.

Copy link
Author

@martyphee martyphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at this for a couple years now. If you find it useful I can fix things up but I'm not using kinesis anymore.

log.info("Client logging: " + this.message);
}

public Function<String, Boolean> getLogger() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's returning a function

return (m) -> {
                     log.debug(m);
                     return true;
                 };

Not sure a better return type since Function requires one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2.x Issues related to the 2.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants