libcult/documentation/trace
Author: Boris Kolpackov
Keywords: libcult,c++,tracing

The libcult trace library provides a general-purpose program tracing facility. The following code fragment can be found in `libcult/examples/trace`:

    struct foo {};

    std::ostream&
    operator<< (std::ostream& o, foo const&)
    {
      return o << "::foo";
    }

    namespace trace = cult::trace;

    trace::stream tout ("main", 4);

    int
    main ()
    {
      using trace::record;

      trace::log::instance ().level (9);

      record a ("main", 2);
      a << "notationally burdensome";
      tout << a;

      record b ("main", 2);
      tout << (b << "a bit better, but still burdensome");

      tout << (record ("main", 2) << "this is"
               << " somewhat"
               << " twisted but nice to be able to");

      tout << "concise, using default level";

      tout << 9 << "concise, using custom level";

      foo f;

      tout << 3 << f << " " << 5;
    }

Along with the proper implementation, a null implementation is provided which can be used to completely optimize trace code away. For details see the Inlining code away essay.

Copyright © 2005-2008 Boris Kolpackov.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, version 1.2; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.

Last updated on 4 Feb 2008