From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id A9F0D7F72C for ; Sun, 14 Aug 2016 11:17:23 +0200 (CEST) IronPort-PHdr: 9a23:uuejCRxarhClnm/XCy+O+j09IxM/srCxBDY+r6Qd0OsXIJqq85mqBkHD//Il1AaPBtSCrasfwLKG++C4ACpbsM7H6ChDOLV3FDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpqsSVOl4D3Gr1Iesrak7n9UOJ7oheqLAhA5558gHOrHpMdrYe7kJTDnXXoSzB4Nyt9oVo6SVatqFp3cdBVaLnY/ZwFuQAX3wOelo478zztBTFURDHpj5FCj1XwVJ0BF2P1xb3UYvrtTO+/s980ymTMMm8BeQxWD+i5qpvDgTvhSgbLTkh2GDRlsF0yqlcpUTyiQZ4xtueWoCeNPNkcuviO/ZcDUhGWMtKHWQVGIK3b6MGCewMLedR6Y7nqA1d/lOFGQCwCba3mXdzjXjs0Ph/irx5HA== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AjCQC8NrBX/7BbRFBeg0VWfIJ5oS4BAQEBAQEGlwEmhXcCgSw8EAIBAQEBAQEBAV0nQQ6BYwQBEwGCFAEFOj8QCxgJExIPBSghiEgKwG8BAQEBBgEBAQEeBYViPoRXh2yCLwWZPgGGHYhuj02MN4N4NR+CEhyBTTsyg2WDDQEBAQ X-IPAS-Result: A0AjCQC8NrBX/7BbRFBeg0VWfIJ5oS4BAQEBAQEGlwEmhXcCgSw8EAIBAQEBAQEBAV0nQQ6BYwQBEwGCFAEFOj8QCxgJExIPBSghiEgKwG8BAQEBBgEBAQEeBYViPoRXh2yCLwWZPgGGHYhuj02MN4N4NR+CEhyBTTsyg2WDDQEBAQ X-IronPort-AV: E=Sophos;i="5.28,519,1464645600"; d="scan'208";a="230273481" Received: from annexia.org ([80.68.91.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 14 Aug 2016 11:17:23 +0200 Received: from rich by annexia.org with local (Exim 4.84_2) (envelope-from ) id 1bYrXj-0000vb-VH; Sun, 14 Aug 2016 10:17:19 +0100 Date: Sun, 14 Aug 2016 10:17:19 +0100 From: "Richard W.M. Jones" To: "Soegtrop, Michael" Cc: "caml-list@inria.fr" Message-ID: <20160814091719.GE27249@annexia.org> References: <0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46@IRSMSX102.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0F7D3B1B3C4B894D824F5B822E3E5A172CF39E46@IRSMSX102.ger.corp.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [Caml-list] Question on Printf wrappers On Fri, Aug 12, 2016 at 12:44:51PM +0000, Soegtrop, Michael wrote: > Dear Ocaml Users, > > it is quite common to have wrappers for printf to e.g. print errors or warnings with some context. Prefixing is easy to do in OCaml (honestly it took me a short while to figure it out): > > let prefixprintf (oc : out_channel) (fmt : ('a, out_channel, unit) format) : 'a = > Printf.fprintf oc "Prefix: "; > Printf.fprintf oc fmt > ;; As Kakadu said, you should look into the ksprintf function. There are several real world examples of useful warning/error/debug/ message functions, if you start at this link and search down the file for 'ksprintf': https://github.com/libguestfs/libguestfs/blob/master/mllib/common_utils.ml#L355 The functions display ANSI colours and do line wrapping. The corresponding type signatures can be found in: https://github.com/libguestfs/libguestfs/blob/master/mllib/common_utils.mli Rich.