3 parses /etc/syslog.conf
5 Author: Mathieu Arnold <mat@FreeBSD.org>
8 This lens tries to keep as close as possible to `man 5 resolv.conf` where possible.
9 An online source being :
10 http://www.freebsd.org/cgi/man.cgi?query=syslog.conf&sektion=5
13 This file is licensed under the BSD License.
18 About: Configuration files
19 This lens applies to /etc/syslog.conf. See <filter>.
25 (************************************************************************
26 * Group: USEFUL PRIMITIVES
27 *************************************************************************)
29 (* Group: Comments and empty lines *)
32 let empty = Util.empty
35 (* Variable: sep_tab *)
36 let sep_tab = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ "\t"
38 (* Variable: sep_tab_opt *)
39 let sep_tab_opt = del /([ \t]*|[ \t]*\\\\\n[ \t]*)/ ""
42 Map comments into "#comment" nodes
43 Can't use Util.comment as #+ and #! have a special meaning.
44 However, '# !' and '# +' have no special meaning so they should be allowed.
47 let comment_gen (space:regexp) (sto:regexp) =
48 [ label "#comment" . del (Rx.opt_space . "#" . space) "# "
52 let comment_withsign = comment_gen Rx.space /([!+-].*[^ \t\n]|[!+-])/
53 in let comment_nosign = comment_gen Rx.opt_space /([^ \t\n+!-].*[^ \t\n]|[^ \t\n+!-])/
54 in comment_withsign | comment_nosign
56 (* Group: single characters macro *)
59 Deletes a comma and default to it
61 let comma = sep_tab_opt . Util.del_str "," . sep_tab_opt
63 Deletes a colon and default to it
65 let colon = sep_tab_opt . Util.del_str ":" . sep_tab_opt
66 (* Variable: semicolon
67 Deletes a semicolon and default to it
69 let semicolon = sep_tab_opt . Util.del_str ";" . sep_tab_opt
71 Deletes a dot and default to it
73 let dot = Util.del_str "."
75 Deletes a pipe and default to it
77 let pipe = Util.del_str "|"
79 Deletes a plus and default to it
81 let plus = Util.del_str "+"
83 Deletes a bang and default to it
85 let bang = Util.del_str "!"
88 deletes an optional # sign
90 let opt_hash = del /#?/ ""
92 deletes an optional + sign
94 let opt_plus = del /\+?/ ""
96 (* Group: various macros *)
99 our version can't start with [_.-] because it would mess up the grammar
101 let word = /[A-Za-z0-9][A-Za-z0-9_.-]*/
103 (* Variable: comparison
104 a comparison is an optional ! with optionally some of [<=>]
106 let comparison = /(!|[<=>]+|![<=>]+)/
108 (* Variable: protocol
112 let protocol = /@{1,2}/
117 let token = /([A-Za-z0-9]+|\*)/
120 a file begins with a / and get almost anything else after
122 let file_r = /\/[^ \t\n;]+/
124 (* Variable: loghost_r
125 Matches a hostname, that is labels speparated by dots, labels can't
126 start or end with a "-". maybe a bit too complicated for what it's worth *)
127 let loghost_r = /[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*/ |
130 (* Group: Function *)
132 (* View: label_opt_list
133 Uses Build.opt_list to generate a list of labels
136 l:string - the label name
137 r:lens - the lens going after the label
138 s:lens - the separator lens passed to Build.opt_list
140 let label_opt_list (l:string) (r:lens) (s:lens) = Build.opt_list [ label l . r ] s
142 (* View: label_opt_list_or
143 Either label_opt_list matches something or it emits a single label
144 with the "or" string.
147 l:string - the label name
148 r:lens - the lens going after the label
149 s:lens - the separator lens passed to Build.opt_list
150 or:string - the string used if the label_opt_list does not match anything
152 let label_opt_list_or (l:string) (r:lens) (s:lens) (or:string) =
153 ( label_opt_list l r s | [ label l . store or ] )
156 (************************************************************************
157 * Group: LENSE DEFINITION
158 *************************************************************************)
160 (* Group: selector *)
163 a list of facilities, separated by commas
165 let facilities = label_opt_list "facility" (store token) comma
168 a selector is a list of facilities, an optional comparison and a level
170 let selector = facilities . dot .
171 [ label "comparison" . store comparison]? .
172 [ label "level" . store token ]
175 a list of selectors, separated by semicolons
177 let selectors = label_opt_list "selector" selector semicolon
182 a file may start with a "-" meaning it does not gets sync'ed everytime
184 let file = [ Build.xchgs "-" "no_sync" ]? . [ label "file" . store file_r ]
187 a loghost is an @ sign followed by the hostname and a possible port
189 let loghost = [label "protocol" . store protocol] . [ label "hostname" . store loghost_r ] .
190 (colon . [ label "port" . store /[0-9]+/ ] )?
193 a list of users or a "*"
195 let users = label_opt_list_or "user" (store word) comma "*"
198 a log program begins with a pipe
200 let logprogram = pipe . [ label "program" . store /[^ \t\n][^\n]+[^ \t\n]/ ]
203 discards matching messages
205 let discard = [ label "discard" . Util.del_str "~" ]
208 an action is either a file, a host, users, a program, or discard
210 let action = (file | loghost | users | logprogram | discard)
215 an entry contains selectors and an action
217 let entry = [ label "entry" .
218 selectors . sep_tab .
219 [ label "action" . action ] . eol ]
222 entries are either comments/empty lines or entries
224 let entries = (empty | comment | entry )*
226 (* Group: Program matching *)
231 let programs = label_opt_list_or "program" (store word) comma "*"
234 a program begins with an optional hash, a bang, and an optional + or -
236 let program = [ label "program" . opt_hash . bang .
237 ( opt_plus | [ Build.xchgs "-" "reverse" ] ) .
238 programs . eol . entries ]
240 (* Group: Hostname maching *)
245 let hostnames = label_opt_list_or "hostname" (store Rx.word) comma "*"
248 a program begins with an optional hash, and a + or -
250 let hostname = [ label "hostname" . opt_hash .
251 ( plus | [ Build.xchgs "-" "reverse" ] ) .
252 hostnames . eol . entries ]
254 (* Group: Top of the tree *)
257 [ key "include" . sep_tab . store file_r . eol ]
260 generic entries then programs or hostnames matching blocs
262 let lns = entries . ( program | hostname | include )*
265 all you need is /etc/syslog.conf
267 let filter = incl "/etc/syslog.conf"
269 let xfm = transform lns filter