Bumped copyright dates for 2013
[barry.git] / opensync-plugin-0.4x / src / trace.h
blob78d20dca56910dadb0152b429b8cde00298b212d
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>
28 #include "format_check.h"
30 class Trace
32 const char *text, *tag;
33 public:
34 explicit Trace(const char *t) : text(t), tag(0)
36 osync_trace(TRACE_ENTRY, "barry_sync: %s", text);
39 Trace(const char *t, const char *tag) : text(t), tag(tag)
41 osync_trace(TRACE_ENTRY, "barry_sync (%s): %s", tag, text);
44 ~Trace()
46 if( tag )
47 osync_trace(TRACE_EXIT, "barry_sync (%s): %s", tag, text);
48 else
49 osync_trace(TRACE_EXIT, "barry_sync: %s", text);
52 void log(const char *t)
54 osync_trace(TRACE_INTERNAL, "barry_sync: %s", t);
57 void logf(const char *t, ...) BARRY_GCC_FORMAT_CHECK(2, 3)
59 va_list vl;
60 va_start(vl, t);
61 char buffer[2048];
62 int n = vsnprintf(buffer, sizeof(buffer), t, vl);
63 va_end(vl);
64 if( n > -1 && n < (int)sizeof(buffer) )
65 osync_trace(TRACE_INTERNAL, "barry_sync: %s", buffer);
66 else
67 osync_trace(TRACE_INTERNAL, "barry_sync: (trace error, output too long for buffer: %s)", t);
71 #endif