Giter Club home page Giter Club logo

logv's Introduction

Logv

Logv is a cognitively lightweight logging utility for Common Lisp

The most useful form is LOGV, a macro that behaves like PROGN except that it writes each form and its return value to the log.

The following code:

(logv (+ 1 (logv (+ 1 1)))
      (+ 10 10)
      (* 64 64))

will return 4096 and might write something like the following lines to the log:

; [2009/03/27] [19:15:08] [repl-thread]: (+ 1 1) -> 2
; [2009/03/27] [19:15:08] [repl-thread]: (+ 1 (LOGV (+ 1 1))) -> 3
; [2009/03/27] [19:15:08] [repl-thread]: (+ 10 10) -> 20
; [2009/03/27] [19:15:08] [repl-thread]: (* 64 64) -> 4096

LOGVS is like LOGV but understands multiple return values. FORMAT-LOG lets you write to the log with a format string and arguments (like FORMAT).

The behavior of LOGV and LOGVS is controlled by "log settings". Log settings can be changed or accessed with SETF-able function LOG-SETTING. for example the following code:

(setf (log-setting :log-output) "/path/to/log.txt")

makes LOGV, LOGVS, and FORMAT-LOG write to the log file "log.txt"

If the :LOG-OUTPUT setting is:

  • T then things that write to the log write to *STANDARD-OUTPUT*
  • NIL then things that normally write to the log don't do anything
  • a stream then things that write to the log write to the stream
  • a pathname designator (a pathname or a string): then things that write to the log write to the file pointed to by the string/pathname. the file is created if it doesn't already exist. if there are special characters they are encoded in UTF-8

The :LOG-PREFIX-STRING-FACTORY setting is a thunk [unary function] that returns a string to be prepended to the log line.

The macro DEF-LOG-ENV enables you to easily roll your own LOGV/LOGVS/FORMAT-LOG like functions and macros. eg:

(def-log-env :my-log (:logv-macro-name my-logv
                      :logvs-macro-name my-logvs
                      :format-log-function-name my-format-log)
   :log-output "/path/to/log.txt"                         ; optional, defaults to t
   :log-prefix-string-factory #<function (lambda ()...>)> ; optional
)

You can then set the log settings of your new log enviroment by adding another arg to LOG-SETTING:

(setf (log-setting :log-output :my-log) "/path/to/mylog.txt")

License

BSD. See "license.txt"

logv's People

Contributors

atgreen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.