You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-2
Original file line number
Diff line number
Diff line change
@@ -2055,6 +2055,15 @@ nil
2055
2055
2056
2056
If you call `slog-to` with a filename destination*outside* the dynamic extent of `logging` or `closing-opened-log-files` then you perhaps want to call `(close-open-log-files :reset t)` every once in a while as well (the `reset` argument doesn't really matter, but it cleans up the map).
2057
2057
2058
+
**`log-file-truename`** is a little utility function: it will return the `truename` of a filename designator, making sure any needed directories are created and creating & opening the file if need be. It's useful just so user code does not need to duplicate what `slog` does, and particularly if you're calling `slog-to` explicitly in situations like:
2059
+
2060
+
```lisp
2061
+
(let ((logname (log-file-truename "my-log.log")))
2062
+
... perhaps change directory etc ...
2063
+
(slog-to logname ...)
2064
+
...)
2065
+
```
2066
+
2058
2067
Finally note that all this mechanism is only about filename destinations: if you log to stream destinations you need to manage the streams as you normally would. The purpose of it is so you can simply not have to worry about the streams but just specify what log file(s) you want written.
2059
2068
2060
2069
### Checking the log file map is sane
@@ -2122,10 +2131,28 @@ There are some sanity tests for this code which are run on loading `slog`, becau
2122
2131
2123
2132
You can use `get-precision-universal-time` to write your own formatters, using `log-entry-internal-time` to get the time the entry was created.
2124
2133
2134
+
### An example: rotating log files
2135
+
```lisp
2136
+
(defun rotate-log-files (&key (all nil))
2137
+
;; Obviously this would want to be more careful in real life
A previous version `slog` handled files rather differently: it tried to delay creating or opening them as long as possible, and thus needed to be able to find an absolute pathname for a file which it had not opened or created, requiring it to have a notion of the current directory which was better than `*default-pathname-defaults*`. This is now all gone: the current version simply treats pathnames as they are.
2153
+
A previous version of `slog` handled files rather differently: it tried to delay creating or opening them as long as possible, and thus needed to be able to find an absolute pathname for a file which it had not opened or created, requiring it to have a notion of the current directory which was better than `*default-pathname-defaults*`. This is now all gone: the current version simply treats pathnames as they are.
2127
2154
2128
-
Condition objects are meant to be immutable (from the [CLHS](http://www.lispworks.com/documentation/HyperSpec/Body/m_defi_5.htm"define-condition"):
2155
+
Condition objects are meant to be immutable: from the [CLHS](http://www.lispworks.com/documentation/HyperSpec/Body/m_defi_5.htm"define-condition")
2129
2156
2130
2157
> The consequences are unspecified if an attempt is made to assign the slots by using `setf`.
0 commit comments