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

is any simple way how to extend the logging message in Bukdu? #116

Open
wookay opened this issue Jul 20, 2021 · 2 comments
Open

is any simple way how to extend the logging message in Bukdu? #116

wookay opened this issue Jul 20, 2021 · 2 comments

Comments

@wookay
Copy link
Owner

wookay commented Jul 20, 2021

Roman Samarev
Hi, is any simple way how to extend the logging message in Bukdu? I need to add a date/time
log(str) = "$(Dates.format(Dates.now(), "yyyy-mm-dd HH:MM:SS")): $(str)"
@wookay
Copy link
Owner Author

wookay commented Jul 21, 2021

using Bukdu # Plug plug
using Logging: AbstractLogger
using Dates
using HTTP

struct MyLogger <: AbstractLogger
    stream
end

function Plug.Loggers.info_response(logger::MyLogger, conn::Conn, route::Bukdu.RouteAction)
    io = logger.stream
    Base.print(io, "$(Dates.format(Dates.now(), "yyyy-mm-dd HH:MM:SS")): ")
    Plug.Loggers.default_info_response(io, conn, route)
    Base.flush(io)
end

function Plug.Loggers.print_message(logger::MyLogger, args...; kwargs...)
    io = logger.stream
    Base.print(io, "$(Dates.format(Dates.now(), "yyyy-mm-dd HH:MM:SS")): ")
    Base.println(io, args...; kwargs...)
    Base.flush(io)
end

plug(MyLogger, stdout)

Bukdu.start(8193)

routes() do
    get("/") do conn::Conn
        render(Text, "ok")
    end
end

HTTP.get("http://127.0.0.1:8193/")
Bukdu.stop()

@wookay
Copy link
Owner Author

wookay commented Jul 21, 2021

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

1 participant