All Projects → nberger → Ring Logger

nberger / Ring Logger

Licence: epl-1.0
Log ring requests & responses using your favorite logging backend

Programming Languages

clojure
4091 projects
ring
36 projects

Projects that are alternatives of or similar to Ring Logger

Log
Structured logging package for Go.
Stars: ✭ 1,094 (+1557.58%)
Mutual labels:  logging
Hslogger
Logging framework for Haskell
Stars: ✭ 60 (-9.09%)
Mutual labels:  logging
Class Logger
Boilerplate-free decorator-based class logging
Stars: ✭ 64 (-3.03%)
Mutual labels:  logging
Wp Rest Api Log
WordPress plugin for logging REST API requests and responses
Stars: ✭ 58 (-12.12%)
Mutual labels:  logging
Log
Fancy logging library for Scala
Stars: ✭ 60 (-9.09%)
Mutual labels:  logging
Logvac
Simple, lightweight, api-driven log aggregation service with realtime push capabilities and historical persistence.
Stars: ✭ 61 (-7.58%)
Mutual labels:  logging
Heroku Logger
A dead simple logger, designed to be perfect for Heroku apps.
Stars: ✭ 57 (-13.64%)
Mutual labels:  logging
Logging Log4j2
Apache Log4j 2 is an upgrade to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides many of the improvements available in Logback while fixing some inherent problems in Logback's architecture.
Stars: ✭ 1,133 (+1616.67%)
Mutual labels:  logging
Log Pilot
Collect logs for docker containers
Stars: ✭ 1,112 (+1584.85%)
Mutual labels:  logging
Terraform Modules
Reusable Terraform modules
Stars: ✭ 63 (-4.55%)
Mutual labels:  logging
Bulk
👨‍💻 Bulk is a library for buffering the objects. Pipeline(Sink) receives the object and emits the object bulked.
Stars: ✭ 59 (-10.61%)
Mutual labels:  logging
Pioneer Console Boilerplate
Dependency injection, logging and configuration in a .NET Core console application.
Stars: ✭ 60 (-9.09%)
Mutual labels:  logging
Node Draftlog
📜 Create updatable log lines into the terminal, and give life to your logs!
Stars: ✭ 1,117 (+1592.42%)
Mutual labels:  logging
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-12.12%)
Mutual labels:  logging
Cookiecutter Pyramid Talk Python Starter
An opinionated Cookiecutter template for creating Pyramid web applications starting way further down the development chain. This cookiecutter template will create a new Pyramid web application with email, sqlalchemy, rollbar, and way more integrated.
Stars: ✭ 64 (-3.03%)
Mutual labels:  logging
Events
Go package for routing, formatting and publishing events produced by a program.
Stars: ✭ 57 (-13.64%)
Mutual labels:  logging
Beauty
A microframework based on mymysql,net/http,jwt-go and mux.
Stars: ✭ 61 (-7.58%)
Mutual labels:  logging
Litter
Litter is a pretty printer library for Go data structures to aid in debugging and testing.
Stars: ✭ 1,137 (+1622.73%)
Mutual labels:  logging
Spring Higher Order Components
⚡️ Preconfigured components to speedup Spring Boot development
Stars: ✭ 65 (-1.52%)
Mutual labels:  logging
Angle Grinder
Slice and dice logs on the command line
Stars: ✭ 1,118 (+1593.94%)
Mutual labels:  logging

Ring-logger Circle CI

Ring middleware to log response time and other details of each request that arrives to your server.

  • Logs request start, finish, parameters and exceptions by default.
  • The user can choose which of those messages to log by using the more specific middleware.
  • "Logs as data": Log messages are simple clojure maps. You can provide a transform-fn to transform to other representations (string, JSON).
  • Uses clojure.tools.logging by default, accepts a log-fn for switching to other log backends (timbre, etc.)

DOCUMENTATION | 0.7.x

Clojars Project

Getting started

Add the dependency to your project:

    [ring-logger "1.0.1"]

Usage

Add the middleware to your ring stack:

    (ns foo
      (:require [ring.adapter.jetty :as jetty]
                [ring.logger :as logger]))

    (defn my-ring-app [request]
         {:status 200
          :headers {"Content-Type" "text/html"}
          :body "Hello world!"})

    (jetty/run-jetty (logger/wrap-with-logger my-ring-app) {:port 8080})

Example output:

INFO  ring.logger: {:request-method :get, :uri "/", :server-name "localhost", :ring.logger/type :starting}                                                                                                  
DEBUG ring.logger: {:request-method :get, :uri "/", :server-name "localhost", :ring.logger/type :params, :params {:name "ring-logger", :password "[REDACTED]"}}                                             
INFO  ring.logger: {:request-method :get, :uri "/", :server-name "localhost", :ring.logger/type :finish, :status 200, :ring.logger/ms 11}

Advanced usage

ring.logger comes with more fine-grained middleware apart from wrap-with-logger:

  • wrap-log-request-start: Logs the start of the request
  • wrap-log-response
  • wrap-log-request-params: Logs the request parameters, using redaction to hide sensitive values (passwords, tokens, etc)

To log just the start and finish of requests (no parameters):

    (-> handler
        logger/wrap-log-response
        ;; more middleware to parse params, cookies, etc.
        logger/wrap-log-request-start)

To measure request latency, wrap-log-response will use the ring.logger/start-ms key added by wrap-log-request-start if both middlewares are being used, or will call System/currentTimeMillis to obtain the value by itself.

Using other loggging backends

Other logging backends can be plugged by passing the log-fn option. This is how you could use timbre instead of c.t.logging:

    (require '[timbre.core :as timbre])

    (-> handler
        (logger/wrap-log-response {:log-fn (fn [{:keys [level throwable message]}]
                                             (timbre/log level throwable message))}))

What gets logged

  • an :info level message when a request begins.
  • a :debug level message with the request parameters (redacted).
  • an :info level message when a response is returned without server errors (i.e. its HTTP status is < 500), otherwise an :error level message is logged.
  • an :error level message with a stack trace when an exception is thrown during response generation.

All messages will be usually timestamped by your logging infrastructure.

How to disable exceptions logging

This is especially useful when also using ring.middleware.stacktrace.

(wrap-with-logger app {:log-exceptions? false})

Password: "[REDACTED]"

Sensitive information in params and headers can be redacted before it's sent to the logs.

This is very important: Nobody wants user passwords or authentication tokens to get to the logs and live there forever, in plain text, right?

By default, ring-logger will redact any parameter whose name is in the ring.logger/default-redact-key? set (:password, :token, :secret, etc). You can pass your own set or function to determine which keys to redact as the redact-key? option

(wrap-with-logger app {:redact-key? #{:senha :token})

Logging only certain requests

If you wish to restrict logging to certain paths (or other conditions), combine ring-logger with ring.middleware.conditional, like so:

(:require [ring.middleware.conditional :as c :refer  [if-url-starts-with
                                                      if-url-doesnt-start-with
                                                      if-url-matches
                                                      if-url-doesnt-match]])

(def my-ring-app
   (-> handler
       (if-url-starts-with "/foo" wrap-with-logger)

        ;; Or:
        ;; (c/if some-test-fn wrap-with-logger)
        ;; etc.

       wrap-with-other-handler))

Consult the ring.middleware.conditional docs for full details.

Similar projects

pjlegato/ring.middleware.logger: ring-logger started as a fork of ring.middleware.logger. It's a great option if you don't mind pulling a transitive dependency on onelog & log4j.

lambdaisland/ring.middleware.logger: a fork of r.m.logger that replaces onelog with clojure.tools.logging

Contributing

Pull requests are welcome!

License

Copyright (C) 2015-2018 Nicolás Berger Copyright (C) 2012-2014 Paul Legato.

Distributed under the Eclipse Public License, the same as Clojure.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].