Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cl-syslog Reference Manual, version 0.2.4, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 04:04:46 2022 GMT+0.
Next: Systems, Previous: The cl-syslog Reference Manual, Up: The cl-syslog Reference Manual [Contents][Index]
Common Lisp interface to local and remote Syslog facilities.
The source files are relatively well documented, so we recommend looking at them, but here's a quickstart guide.
To load cl-syslog
, use Quicklisp or ASDF as usual:
> (ql:quickload :cl-syslog)
;; or, if ASDF can already see it:
> (asdf:load-system :cl-syslog)
Priorities and facilities are stated by their keyword name. For
instance, the priority :warning
on facility :user
. All of these
keywords are housed in the variables *priorities*
and
*variables*
. Should you provide invalid facilities or priorities,
the conditions cl-syslog:invalid-facility
and
cl-syslog:invalid-priority
will be signaled.
To log to your local syslog daemon, use cl-syslog:log
(note that
this is shadowed, and is obviously not the same as cl:log
!):
> (cl-syslog:log "MyApp" ':user ':warning "Low on memory.")
Then look in your /var/log/messages
or other location if you have
tweaked your /etc/syslog.conf
. On macOS, you can use the Console
application.
RFC 5424 is supported. (You can check if your CL-SYSLOG installation
support it by checking if cl-syslog::rfc5424
is present in your
*features*
.)
The first thing you'll need to do is create an instance of the
rfc5424-logger
class, filling out as many details as you
please. You're encouraged to fill out as many slots as you can so that
log messages contain more information.
Of particular interest is the :log-writer
initarg. This controls how
log messages get processed in the end. The default log writer will use
a function wrapping cl-syslog:log
. Should you instead be interested
in writing to standard output, you can supply
(cl-syslog:stream-log-writer)
as an argument, like so:
(defparameter *logger*
(make-instance 'cl-syslog:rfc5424-logger
;; optional
:facility ':local0
:app-name "MyApp"
:hostname "computer.local"
:log-writer (cl-syslog:stream-log-writer)))
There are a few options for log writers, including a UDP log writer
for remote RFC-compliant logging. You can always support your own
lambda
function, too.
Once you have a logger, the simplest way to create a compliant message
is to use cl-syslog:format-log
:
> (cl-syslog:format-log *logger* ':warning "Low on memory.")
<132>1 2018-12-13T22:17:56Z computer.local MyApp 69840 - - Low on memory.
RFC 5424 has support for sending structured data within the log
message. It's a somewhat complicated arrangement, in that the
structured data has to be defined and "agreed upon". Specifically,
there are a set of IETF-approved structured data. They're identified
by "structured data IDs", and the standard IDs are timeQuality
,
origin
, and meta
. Each of these have different structured data
parameters.
Personal structured data IDs must have some name, followed by @
,
followed by a usually 4 or 5 digit integer. For instance,
mycompany@0001
is a valid personal structured data ID. One can
define a structured data ID using
cl-syslog:define-structured-data-id
. The definition of the standard
origin
ID is:
(define-structured-data-id |origin| (:standard t)
(|ip| :allow-repetitions t
:validator 'ip-address-p)
|enterpriseId|
(|software| :length (integer 0 40))
(|swVersion| :length (integer 0 32)))
(This can be seen in the file rfc5424-reserved.lisp
.)
Your own structured data ID might be:
(cl-syslog:define-structured-data-id |mycompany@0001| ()
|who|
|what|)
Note that the field names are escaped to follow the RFC's usual idiom. Also node that the field names are here symbols scoped to your package. CL-SYSLOG exports all of the symbols of the standard ID's.
How can we use these? We use the log macro rfc-log
. It's a macro
because it does extra work at compile time to build code that only
runs if the log message is to be sent.
Suppose we've defined the above structured data ID. Then we might log the following:
> (cl-syslog:rfc-log (*logger* :warning "Running out of memory! I got ~D byte~:P left!" 10)
(cl-syslog:|origin|
cl-syslog:|ip| "1.2.3.4"
cl-syslog:|software| "My Testing App"
cl-syslog:|swVersion| "12.2")
(|mycompany@0001|
|who| "John Doe"
|what| "Needs to buy a new computer."))
;; output:
<132>1 2018-12-13T22:28:02Z computer.local MyApp 69840 - [origin ip="1.2.3.4" software="My Testing App" swVersion="12.2"][mycompany@0001 who="John Doe" what="Needs to buy a new computer."] Running out of memory! I got 10 bytes left!
Optionally, a message ID string can be supplied. This is useful if the
message is a part of a category of similar messages. Suppose the
message ID is "LOG1234"
, then we could write the above message as:
> (cl-syslog:rfc-log (*logger* :warning "Running out of memory! I got ~D byte~:P left!" 10)
(:msgid "LOG1234")
(cl-syslog:|origin|
cl-syslog:|ip| "1.2.3.4"
cl-syslog:|software| "My Testing App"
cl-syslog:|swVersion| "12.2")
(|mycompany@0001|
|who| "John Doe"
|what| "Needs to buy a new computer."))
;; output:
<132>1 2018-12-13T22:29:36Z computer.local MyApp 69840 LOG1234 [origin ip="1.2.3.4" software="My Testing App" swVersion="12.2"][mycompany@0001 who="John Doe" what="Needs to buy a new computer."] Running out of memory! I got 10 bytes left!
Currently, Unicode isn't properly handled. It is expected all data is
ASCII. It is also expect that your Lisp's char-code
matches
ASCII. The necessary BOM will not be inserted for Unicode.
The RFC 5424 log handling functions generally write to streams, but the entry points cons up strings (if and only if the log message is actually sent). There is currently no support for allowing streaming log data at the log generation level.
Many log processors do not implement all of RFC 5424, but nonetheless
cope rather well with the format, and can understand the RFC's
key=value
pairs.
The raw C interfaces are CFFI-accessible by their standard UNIX names:
openlog
, closelog
, and syslog
. None of these are necessary
unless you are looking for complete control. Beware, if you mess these
calls up, you will break your Lisp process.
Next: Files, Previous: Introduction, Up: The cl-syslog Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Common Lisp syslog interface.
Erik Enge, Mike Maul, Robert Smith
MIT (See LICENSE)
0.2.4
Next: Packages, Previous: Systems, Up: The cl-syslog Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: cl-syslog/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
cl-syslog (system).
Next: cl-syslog/variable.lisp, Previous: cl-syslog/cl-syslog.asd, Up: Lisp [Contents][Index]
cl-syslog (system).
Next: cl-syslog/cl-syslog.lisp, Previous: cl-syslog/package.lisp, Up: Lisp [Contents][Index]
cl-syslog (system).
Next: cl-syslog/rfc5424.lisp, Previous: cl-syslog/variable.lisp, Up: Lisp [Contents][Index]
cl-syslog (system).
Next: cl-syslog/rfc5424-reserved.lisp, Previous: cl-syslog/cl-syslog.lisp, Up: Lisp [Contents][Index]
cl-syslog (system).
Previous: cl-syslog/rfc5424.lisp, Up: Lisp [Contents][Index]
cl-syslog (system).
Next: Definitions, Previous: Files, Up: The cl-syslog Reference Manual [Contents][Index]
Packages are listed by definition order.
Common Lisp interface to syslog.
syslog
common-lisp.
Next: Indexes, Previous: Packages, Up: The cl-syslog Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Macros, Previous: Public Interface, Up: Public Interface [Contents][Index]
Log on the console if errors in sending.
Don’t delay open.
Don’t wait for console forks: deprecated.
Delay open until first syslog() (default).
Log to stderr as well.
Log the pid with each message.
Next: Ordinary functions, Previous: Constants, Up: Public Interface [Contents][Index]
Define a new structured data ID named ID-NAME.
ALLOW-OTHER-PARAMS is an option to allow other named parameters to be present.
STANDARD is an option to dictate that the defined message is an IETF-reserved name.
BODY specifies the fields and has the following syntax:
<body> ::= <field>*
<field> ::= <symbol>
| (<symbol> [:allow-repetitions <boolean>]
[:length <length-type>]
[:validator <form>])
<length-type> ::= an unevaluated form that is a subtype of UNSIGNED-BYTE
<form> ::= an evaluated form producing a funcallable unary function mapping to booleans
The :ALLOW-REPETITIONS keyword allows a field to be repeated (default: nil).
The :LENGTH keyword specifies what the length of the string data must satisfy. By default it’s unbounded by UNSIGNED-BYTE.
The :VALIDATOR keyword allows a validating function to be provided. By default it is (CONSTANTLY T).
Log the message formed by CONTROL and ARGS to the logger LOGGER with priority PRIORITY. Structured data should be a list of structured data clauses of the form, where each clause has the form:
(:MSGID <string>)
or
(<ID> <PARAM 1> <VALUE 1>
<PARAM 2> <VALUE 2>
...)
The data <ID> and <PARAM n> are symbols, while <VALUE n> are strings. Both <ID> and <PARAM n> are *not* evaluated, while <VALUE n> are evaluated.
If :MSGID is provided, then this will be the RFC5424 msgid of the log message.
The logging will only happen of LOGGER does not exceed a specified maximum priority value.
Next: Generic functions, Previous: Macros, Up: Public Interface [Contents][Index]
Return facility number given the facility’s name. If there is no such facility, signal ‘invalid-facility’ error.
Return priority number given the priority’s name. If there is no such priority, signal ‘invalid-priority’ error.
Create a new log writer (for an RFC5424-LOGGER instance) joining the effects of each of the supplied log writers WRITERS.
Print message to syslog.
’option’ can be any of the +log...+ constants
Create a log writer (for an RFC5424-LOGGER instance) that does nothing.
Create a log function (for an RFC5424-LOGGER instance) that writes to STREAM. By default this is *STANDARD-OUTPUT*.
Create a log writer (for an RFC5424-LOGGER instance) that writes to the system’s syslog.
Create a log writer (for an RFC5424-LOGGER instance) that writes to STREAM, but is also processed by LOG-WRITER.
Create a log writer (for an RFC5424-LOGGER instance) that writes to the UDP endpoint HOST on poort PORT.
Next: Standalone methods, Previous: Ordinary functions, Up: Public Interface [Contents][Index]
Return values YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, FRACTION-OF-A-SECOND.
Log the simple message STRING according to the priority PRIORITY. Note that this function behaves like CL:FORMAT, so ~’s in the CONTROL string will be interpreted as such.
This should be used in the simplest of logging situations. For more complicated log messages that contain structured data, see the RFC-LOG macro.
Next: Conditions, Previous: Generic functions, Up: Public Interface [Contents][Index]
Next: Classes, Previous: Standalone methods, Up: Public Interface [Contents][Index]
error.
error.
error.
:violated-assertion
This slot is read-only.
Previous: Conditions, Up: Public Interface [Contents][Index]
Class holding the state to construct and transmit an RFC 5424-compliant log message.
Initarg | Value |
---|---|
:facility | (quote user) |
:maximum-priority | (quote info) |
:hostname | (machine-instance) |
:app-name | nil |
:process-id | (prin1-to-string (getpid)) |
:log-writer | nil |
The syslog facility, as a keyword.
:facility
This slot is read-only.
The maximum priority above which log messages are not emitted to the external logging facility. The default maximum priority is :INFO. (Recall that priorities of *increasing* severity have *decreasing* priority values.)
:maximum-priority
This slot is read-only.
:hostname
This slot is read-only.
:app-name
This slot is read-only.
:process-id
This slot is read-only.
A binary function that takes a priority keyword and a string and returns an unspecified value. This is the function that received log messages and does whatever is desired. A NIL initarg (the default) means strings will be logged to syslog with the associated facility (as if by SYSLOG-LOG-WRITER).
Example: A value of (CONSTANTLY NIL) is appropriate if no action is desired.
Example: A value akin to (lambda (p s) (write-line s)) is appropriate if all log messages should go to *STANDARD-OUTPUT*. Note that this can be done with (STREAM-LOG-WRITER).
Note: This isn’t a "writer" in the usual CLOS sense.
See also: The functions NULL-LOG-WRITER, SYSLOG-LOG-WRITER, STREAM-LOG-WRITER, TEE-TO-STREAM, UDP-LOG-WRITER.
:log-writer
This slot is read-only.
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Special variables, Previous: Internals, Up: Internals [Contents][Index]
The RFC 5424 "NILVALUE".
Next: Ordinary functions, Previous: Special variables, Up: Internals [Contents][Index]
Next: Generic functions, Previous: Macros, Up: Internals [Contents][Index]
Is the string STRING a valid enterprise number?
Is X a valid structured data ID? Roughly, these are either:
1. A bare ASCII name, in which case it’s an IETF-reserved name.
2. An ASCII name, followed by ’@’, followed by a number (which may have dots).
Return two values:
1. A Boolean indicating whether it’s a valid ID.
2. A Boolean indicating whether its name conforms to an IETF-reserved name.
Write out the PARAM-NAME STRING to the stream STREAM.
Write out the PARAM-VALUE STRING to the stream STREAM.
Write the RFC 5424-compliant syslog message to the stream STREAM.
Next: Structures, Previous: Ordinary functions, Up: Internals [Contents][Index]
automatically generated reader method
The syslog facility, as a keyword.
automatically generated reader method
A binary function that takes a priority keyword and a string and returns an unspecified value. This is the function that received log messages and does whatever is desired. A NIL initarg (the default) means strings will be logged to syslog with the associated facility (as if by SYSLOG-LOG-WRITER).
Example: A value of (CONSTANTLY NIL) is appropriate if no action is desired.
Example: A value akin to (lambda (p s) (write-line s)) is appropriate if all log messages should go to *STANDARD-OUTPUT*. Note that this can be done with (STREAM-LOG-WRITER).
Note: This isn’t a "writer" in the usual CLOS sense.
See also: The functions NULL-LOG-WRITER, SYSLOG-LOG-WRITER, STREAM-LOG-WRITER, TEE-TO-STREAM, UDP-LOG-WRITER.
The maximum priority above which log messages are not emitted to the external logging facility. The default maximum priority is :INFO. (Recall that priorities of *increasing* severity have *decreasing* priority values.)
automatically generated reader method
Next: Types, Previous: Generic functions, Up: Internals [Contents][Index]
A description of structured data.
structure-object.
alexandria:string-designator
This slot is read-only.
boolean
t
This slot is read-only.
alexandria:proper-list
This slot is read-only.
A description of a field of structured data.
structure-object.
alexandria:string-designator
This slot is read-only.
boolean
This slot is read-only.
(quote unsigned-byte)
This slot is read-only.
(or symbol function)
(constantly t)
This slot is read-only.
Previous: Structures, Up: Internals [Contents][Index]
Previous: Definitions, Up: The cl-syslog Reference Manual [Contents][Index]
Jump to: | (
A C D F G I J L M N O P R S T U V W |
---|
Jump to: | (
A C D F G I J L M N O P R S T U V W |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
+
A C F H I L M N P R S V |
---|
Jump to: | *
+
A C F H I L M N P R S V |
---|
Jump to: | C F I M P R S T V |
---|
Jump to: | C F I M P R S T V |
---|