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

Custom Access Log For Response #281

Open
EverydayDiesel opened this issue Sep 21, 2022 · 1 comment
Open

Custom Access Log For Response #281

EverydayDiesel opened this issue Sep 21, 2022 · 1 comment

Comments

@EverydayDiesel
Copy link

Hello,

This example shows how to get a custom access log at the time of request. How can I get the information at the response (I need the return HTTP response code ie 200, 404, 418)

    #include <httpserver.hpp>
    #include <iostream>

    using namespace httpserver;

    void custom_access_log(const std::string& url) {
        std::cout << "ACCESSING: " << url << std::endl;
    }

    class hello_world_resource : public http_resource {
    public:
        const std::shared_ptr<http_response> render(const http_request&) {
            return std::shared_ptr<http_response>(new string_response("Hello, World!"));
        }
    };

    int main(int argc, char** argv) {
        webserver ws = create_webserver(8080)
            .log_access(custom_access_log);

        hello_world_resource hwr;
        ws.register_resource("/hello", &hwr);
        ws.start(true);

        return 0;
    }
@Lotharyx
Copy link

More to the point: It would be a nice enhancement to have the log_access and log_error handlers take the request object as the argument (rather than std::string) so that the handler can format the log message as desired.

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