| 9 | ) |
| 10 | |
| 11 | func TestLogDirectiveSyntax(t *testing.T) { |
| 12 | for i, tc := range []struct { |
| 13 | input string |
| 14 | output string |
| 15 | expectError bool |
| 16 | }{ |
| 17 | { |
| 18 | input: `:8080 { |
| 19 | log |
| 20 | } |
| 21 | `, |
| 22 | output: `{"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{}}}}}}`, |
| 23 | expectError: false, |
| 24 | }, |
| 25 | { |
| 26 | input: `:8080 { |
| 27 | log { |
| 28 | core mock |
| 29 | output file foo.log |
| 30 | } |
| 31 | } |
| 32 | `, |
| 33 | output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"writer":{"filename":"foo.log","output":"file"},"core":{"module":"mock"},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`, |
| 34 | expectError: false, |
| 35 | }, |
| 36 | { |
| 37 | input: `:8080 { |
| 38 | log { |
| 39 | format filter { |
| 40 | wrap console |
| 41 | fields { |
| 42 | request>remote_ip ip_mask { |
| 43 | ipv4 24 |
| 44 | ipv6 32 |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | `, |
| 51 | output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"encoder":{"fields":{"request\u003eremote_ip":{"filter":"ip_mask","ipv4_cidr":24,"ipv6_cidr":32}},"format":"filter","wrap":{"format":"console"}},"include":["http.log.access.log0"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"log0"}}}}}}`, |
| 52 | expectError: false, |
| 53 | }, |
| 54 | { |
| 55 | input: `:8080 { |
| 56 | log name-override { |
| 57 | core mock |
| 58 | output file foo.log |
| 59 | } |
| 60 | } |
| 61 | `, |
| 62 | output: `{"logging":{"logs":{"default":{"exclude":["http.log.access.name-override"]},"name-override":{"writer":{"filename":"foo.log","output":"file"},"core":{"module":"mock"},"include":["http.log.access.name-override"]}}},"apps":{"http":{"servers":{"srv0":{"listen":[":8080"],"logs":{"default_logger_name":"name-override"}}}}}}`, |
| 63 | expectError: false, |
| 64 | }, |
| 65 | { |
| 66 | input: `:8080 { |
| 67 | log { |
| 68 | sampling { |