tzwrapper.cc: fixed use of iterator after erase
[barry.git] / opensync-plugin / src / trace.h
blobcc4f482639290109c599f446edd6a8c793741b09
1 //
2 // \file trace.h
3 // RAII class for trace logging.
4 //
6 /*
7 Copyright (C) 2006-2013, 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>
27 #include <stdio.h>
29 class Trace
31 const char *text, *tag;
32 public:
33 explicit Trace(const char *t) : text(t), tag(0)
35 osync_trace(TRACE_ENTRY, "barry_sync: %s", text);
38 Trace(const char *t, const char *tag) : text(t), tag(tag)
40 osync_trace(TRACE_ENTRY, "barry_sync (%s): %s", tag, text);
43 ~Trace()
45 if( tag )
46 osync_trace(TRACE_EXIT, "barry_sync (%s): %s", tag, text);
47 else
48 osync_trace(TRACE_EXIT, "barry_sync: %s", text);
51 void log(const char *t)
53 osync_trace(TRACE_INTERNAL, "barry_sync: %s", t);
56 void logf(const char *t, ...)
58 va_list vl;
59 va_start(vl, t);
60 char buffer[2048];
61 int n = vsnprintf(buffer, sizeof(buffer), t, vl);
62 va_end(vl);
63 if( n > -1 && n < (int)sizeof(buffer) )
64 osync_trace(TRACE_INTERNAL, "barry_sync: %s", buffer);
65 else
66 osync_trace(TRACE_INTERNAL, "barry_sync: (trace error, output too long for buffer: %s)", t);
70 #endif