- upper management directive: revert all OpenSync 0.3x changes
[barry.git] / opensync-plugin / src / trace.h
blob601b9f452b5879d38e78002a993b129a39f309c5
1 //
2 // \file trace.h
3 // RAII class for trace logging.
4 //
6 /*
7 Copyright (C) 2006-2007, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_SYNC_TRACE_H__
23 #define __BARRY_SYNC_TRACE_H__
25 #include <opensync/opensync.h>
26 #include <stdarg.h>
28 class Trace
30 const char *text, *tag;
31 public:
32 explicit Trace(const char *t) : text(t), tag(0)
34 osync_trace(TRACE_ENTRY, "barry_sync: %s", text);
37 Trace(const char *t, const char *tag) : text(t), tag(tag)
39 osync_trace(TRACE_ENTRY, "barry_sync (%s): %s", tag, text);
42 ~Trace()
44 if( tag )
45 osync_trace(TRACE_EXIT, "barry_sync (%s): %s", tag, text);
46 else
47 osync_trace(TRACE_EXIT, "barry_sync: %s", text);
50 void log(const char *t)
52 osync_trace(TRACE_INTERNAL, "barry_sync: %s", t);
55 void logf(const char *t, ...)
57 va_list vl;
58 va_start(vl, t);
59 char buffer[2048];
60 int n = vsnprintf(buffer, sizeof(buffer), t, vl);
61 va_end(vl);
62 if( n > -1 && n < (int)sizeof(buffer) )
63 osync_trace(TRACE_INTERNAL, "barry_sync: %s", buffer);
64 else
65 osync_trace(TRACE_INTERNAL, "barry_sync: (trace error, output too long for buffer: %s)", t);
69 #endif