8000 How to do if want to calculate the request processing time and print it in the log? · Issue #108 · wookay/Bukdu.jl · GitHub
[go: up one dir, main page]

Skip to content

How to do if want to calculate the request processing time and print it in the log? #108

Closed

Description

@biluohc
No description provided.

Activity

  1. wookay commented on Sep 24, 2020

    @wookay
    Owner
    using Bukdu
    
    function Bukdu.System.catch_request(route::Bukdu.Route, conn)
        conn.private[:req_time_ns] = time_ns()
    end
    
    using Logging: AbstractLogger
    
    struct MyLogger <: AbstractLogger
        stream
    end
    
    function Plug.Loggers.info_response(logger::MyLogger, conn, route::NamedTuple{(:controller, :action)})
        io = logger.stream
        proc_time = (time_ns() - conn.private[:req_time_ns]) / 1e9
        print(io, proc_time, ' ')
        Plug.Loggers.default_info_response(io, conn, route)
    end
    
    plug(MyLogger, IOContext(Core.stdout, :color => Plug.Loggers.have_color()))
    
    
    get("/") do conn::Conn
        42
    end
    
    Router.call(get, "/")
    
  2. biluohc commented on Oct 9, 2020

    @biluohc
    Author

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0