@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 59 lines 1.64 KB
Raw
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package logging
16
17 import (
18 "strings"
19
20 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
21 "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
22 "github.com/caddyserver/caddy/v2/modules/caddyhttp"
23 )
24
25 func init() {
26 httpcaddyfile.RegisterHandlerDirective("log_append", parseCaddyfile)
27 }
28
29 // parseCaddyfile sets up the log_append handler from Caddyfile tokens. Syntax:
30 //
31 // log_append [<matcher>] [<]<key> <value>
32 func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
33 handler := new(LogAppend)
34 err := handler.UnmarshalCaddyfile(h.Dispenser)
35 return handler, err
36 }
37
38 // UnmarshalCaddyfile implements caddyfile.Unmarshaler.
39 func (h *LogAppend) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
40 d.Next() // consume directive name
41 if !d.NextArg() {
42 return d.ArgErr()
43 }
44 h.Key = d.Val()
45 if !d.NextArg() {
46 return d.ArgErr()
47 }
48 if strings.HasPrefix(h.Key, "<") && len(h.Key) > 1 {
49 h.Early = true
50 h.Key = h.Key[1:]
51 }
52 h.Value = d.Val()
53 return nil
54 }
55
56 // Interface guards
57 var (
58 _ caddyfile.Unmarshaler = (*LogAppend)(nil)
59 )