<commit_before>;;; logging.clj -- delegated logging for Clojure

;; by <NAME>
;; July 27, 2009

;; Copyright (c) <NAME>, July 2009. All rights reserved.  The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
;; distribution.  By using this software in any fashion, you are
;; agreeing to be bound by the terms of this license.  You must not
;; remove this notice, or any other, from this software.
(ns ^{:author "<NAME>"
      :doc "Logging macros which delegate to a specific logging implementation. At
            runtime a specific implementation is selected from, in order, slf4j,
            Apache commons-logging, slf4j, log4j, and finally java.util.logging."}
  clojure.tools.logging
  [:use
   [clojure.string :only [trim-newline]]
   [clojure.pprint :only [code-dispatch pprint with-pprint-dispatch]]]
  [:require [clojure.tools.logging.impl :as impl]])

(def ^{:doc
  "The default agent used for performing logging when direct logging is
  disabled. See log* for details." :dynamic true}
  *logging-agent* (agent nil :error-mode :continue))

(def ^{:doc
  "The set of levels that will require using an agent when logging from within a
  running transaction. Defaults to #{:info :warn}. See log* for details." :dynamic true}
  *tx-agent-levels* #{:info :warn})

(def ^{:doc
  "Overrides the default rules for choosing between logging directly or via an
  agent. Defaults to nil. See log* for details." :dynamic true}
  *force* nil)

(defn log*
  "Attempts to log a message, either directly or via an agent; does not check if
  the level is enabled.

  For performance reasons, an agent will only be used when invoked within a
  running transaction, and only for logging levels specified by
  *tx-agent-levels*. This allows those entries to only be written once the
  transaction commits, and are discarded if it is retried or aborted.  As
  corollary, other levels (e.g., :debug, :error) will be written even from
  failed transactions though at the cost of repeat messages during retries.

  One can override the above by setting *force* to :direct or :agent; all
  subsequent writes will be direct or via an agent, respectively."
  [logger level throwable message]
  (if (case *force*
        :agent  true
        :direct false
        nil     (and (clojure.lang.LockingTransaction/isRunning)
                     (*tx-agent-levels* level)))
    (send-off *logging-agent*
      (fn [_#] (impl/write! logger level throwable message)))
    (impl/write! logger level throwable message)))

(declare ^{:dynamic true} *logger-factory*) ; default LoggerFactory instance for calling impl/get-logger<commit_msg>Revert from using case since 1.2 breaks with nil test constants.<commit_after>;;; logging.clj -- delegated logging for Clojure

;; by <NAME>
;; July 27, 2009

;; Copyright (c) <NAME>, July 2009. All rights reserved.  The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
;; distribution.  By using this software in any fashion, you are
;; agreeing to be bound by the terms of this license.  You must not
;; remove this notice, or any other, from this software.
(ns ^{:author "<NAME>"
      :doc "Logging macros which delegate to a specific logging implementation. At
            runtime a specific implementation is selected from, in order, slf4j,
            Apache commons-logging, slf4j, log4j, and finally java.util.logging."}
  clojure.tools.logging
  [:use
   [clojure.string :only [trim-newline]]
   [clojure.pprint :only [code-dispatch pprint with-pprint-dispatch]]]
  [:require [clojure.tools.logging.impl :as impl]])

(def ^{:doc
  "The default agent used for performing logging when direct logging is
  disabled. See log* for details." :dynamic true}
  *logging-agent* (agent nil :error-mode :continue))

(def ^{:doc
  "The set of levels that will require using an agent when logging from within a
  running transaction. Defaults to #{:info :warn}. See log* for details." :dynamic true}
  *tx-agent-levels* #{:info :warn})

(def ^{:doc
  "Overrides the default rules for choosing between logging directly or via an
  agent. Defaults to nil. See log* for details." :dynamic true}
  *force* nil)

(defn log*
  "Attempts to log a message, either directly or via an agent; does not check if
  the level is enabled.

  For performance reasons, an agent will only be used when invoked within a
  running transaction, and only for logging levels specified by
  *tx-agent-levels*. This allows those entries to only be written once the
  transaction commits, and are discarded if it is retried or aborted.  As
  corollary, other levels (e.g., :debug, :error) will be written even from
  failed transactions though at the cost of repeat messages during retries.

  One can override the above by setting *force* to :direct or :agent; all
  subsequent writes will be direct or via an agent, respectively."
  [logger level throwable message]
  (if (cond
        (nil? *force*) (and (clojure.lang.LockingTransaction/isRunning)
                            (*tx-agent-levels* level))
        (= *force* :agent)  true
        (= *force* :direct) false)
    (send-off *logging-agent*
      (fn [_#] (impl/write! logger level throwable message)))
    (impl/write! logger level throwable message)))

(declare ^{:dynamic true} *logger-factory*) ; default LoggerFactory instance for calling impl/get-logger
{'fraction_non_alphanumeric': 0.09529724933451642, 'fraction_numerical': 0.00709849157054126, 'mean_word_length': 3.6272577996715927, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3619753', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1577, 'n_words': 729}