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

POST log to a REST-API instead of console.log #18

Open
sedatkilinc opened this issue Apr 7, 2017 · 1 comment
Open

POST log to a REST-API instead of console.log #18

sedatkilinc opened this issue Apr 7, 2017 · 1 comment

Comments

@sedatkilinc
Copy link

This is not really an issue!
Do you have a hint how to implement it to call a service posting the logs?
Your implementation works very fine logging into the console.
I tried to extend it by sending the logs to a server.
It doesn't seem to be possible to inject a request service with ReflectiveInjector.resolveAndCreate.
The properties didn't get set through injecting, so I've got a runtime error.
I think that would break the principles of pure function.
I'm new to this pattern. That's why I couldn't find any solution.
Is there one using your solution?

@christophjohannsdotter
Copy link

You can create a "LogEffect" with dispatch: false, that runs on every action (without filtering with ofType) and PUT/POST the actions to a REST service in this effect.
I suggest to create a "loggable" interface, that actions have to implement in case they want to be logged.

So your effect could look like this:

@Effect({dispatch: false}) public logAllActionsEffect$ = this.action$
        .map((action: Action) => {
            try {
                if (checkIfActionImplementsLoggableInterface(action)) {
                    this.restService.postYourAction(action);
                }
            /**
             * just catch the error, failing logging should not break your stream
             *
             */
            } catch (error) {}


        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants