GithubHelp home page GithubHelp logo

leodido / caddy-conditional-logging Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 398 KB

Caddy log encoder for conditional logging

License: Apache License 2.0

Go 100.00%
caddy caddy-plugin logging log conditional expression-evaluator caddyserver if encoder format

caddy-conditional-logging's People

Contributors

leodido avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mohammed90

caddy-conditional-logging's Issues

Build fails

When trying to build the extension I get this:

#13 146.9 2023/01/23 07:57:24 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath 
#13 160.8 # github.com/leodido/caddy-conditional-logging
#13 160.8 /go/pkg/mod/github.com/leodido/[email protected]/plugin.go:153:14: cannot use ctx.Logger (value of type func(module ...caddy.Module) *zap.Logger) as type func(caddy.Module) *zap.Logger in assignment
#13 163.1 2023/01/23 07:57:41 [INFO] Skipping cleanup as requested; leaving folder intact: /tmp/buildenv_2023-01-23-0754.2686892640

The Dockerfile I use:

FROM caddy:2.6.2-builder AS builder

RUN xcaddy build \
     --with github.com/leodido/caddy-conditional-logging

Project not an official Caddy module

I was trying to use the caddy add-package command to add this plugin to my caddy-server and the command failed with:

Error: download failed: download failed: HTTP 400: github.com/leodido/caddy-conditional-logging is not a registered Caddy module package path (id=5d1b150e-cac2-4ce6-a5af-6ba42eaf1da3

This module also does not show up on Caddy's download page: https://caddyserver.com/download

Investigate why the automatic fallback encoder seems to cause issues to the server

When the user does not specify the Caddy encoder (eg., json or console) to use, this plugin automatically creates one depending on the environment (console if it's run in a terminal, json otherwise).

log {
  format if {
    ts sw 2021
  }
}

Anyways, it seems that in this case the plugin is not working correctly causing the server to terminate the connection.

This does NOT happen in case the user explicitly expresses the encoder:

log {
  format if {
    ts sw 2021
  } console
}

Needs investigation.

Make the conditions work also on non JSON underlying encoders

It's not working (at the moment) when using Caddy encoders other than the json one.

The reason is that the conditions' expressions matching logic expects the buffer to contain JSON data.

To solve this a possible solution would be:

  1. always store a JSON logging encoder from Caddy
  2. obtain the buffer from it
  3. output (when conditions are met) using the desired logging encoder (eg. console)

Child encoder module is hardcoded to only 3 built-in ones

I told some users in caddyserver/transform-encoder#18 (comment) that they could use this plugin along with the transform encoder, but apparently this plugin doesn't allow it because of the switch here:

switch v := val.(type) {

This plugin should allow any encoder module to be a child.

(That said, there's now a skip_log directive built into Caddy since v2.6 so this plugin probably isn't really needed anymore)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.