File: log.ml

package info (click to toggle)
approx 4.5-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 428 kB
  • ctags: 683
  • sloc: ml: 1,957; sh: 45; makefile: 36
file content (23 lines) | stat: -rw-r--r-- 794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(* approx: proxy server for Debian archive files
   Copyright (C) 2010  Eric C. Cooper <ecc@cmu.edu>
   Released under the GNU General Public License *)

open Util
open Syslog

let facility = facility_of_string Config.syslog
let log = openlog ~facility (Filename.basename Sys.argv.(0))

let message enabled level =
  (* ensure message is newline-terminated,
     otherwise syslog-ng behaves differently than syslog *)
  let terminate str =
    let n = String.length str in
    if n = 0 || str.[n - 1] <> '\n' then str ^ "\n"
    else str
  in
  Printf.ksprintf (fun str -> if enabled then syslog log level (terminate str))

let error_message fmt = message true `LOG_ERR fmt
let info_message fmt = message Config.verbose `LOG_INFO fmt
let debug_message fmt = message Config.debug `LOG_DEBUG fmt