1 /* Copyright (C) 2003 TSUTSUMI Kikuo.
2 This file is part of the CCUnit Library.
4 The CCUnit Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License
6 as published by the Free Software Foundation; either version 2.1 of
7 the License, or (at your option) any later version.
9 The CCUnit Library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the CCUnit Library; see the file COPYING.LESSER.
16 If not, write to the Free Software Foundation, Inc., 59 Temple
17 Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <ccunit/CCUnitLogMessage.h>
31 bool _ccunit_debug_message = false;
34 * verbose message flag.
36 bool _ccunit_verbose_message = false;
39 * return stack growing direction.
41 * @param caller stack variable address of caller function.
43 * @return 1 when stack growing up, -1 when stack growing down.
45 static int stackdir (const int* caller)
47 auto const int stack = 0;
48 return caller < &stack ? 1 : -1;
52 * count msg function call nestings
54 * @return 1 when function nested, -1 when function returned, 0 when
55 * function is same level.
57 static int nestings ()
59 auto const int stack = 0;
60 static const int* previous = NULL;
64 dir = stackdir (&stack);
67 else if (previous < &stack)
69 else if (previous > &stack)
80 * @param prompt message prompt string.
81 * @param fmt message format string for printf.
82 * @param args message arguments.
84 static void msg (const char* prompt, const char* fmt, va_list args)
86 static int leader = 1;
88 leader += nestings () * inc;
89 fprintf (stderr, "%s:%*c", prompt, leader, ' ');
90 vfprintf (stderr, fmt, args);
94 inline void ccunit_dbg (const char* fmt, ...)
96 if (_ccunit_debug_message)
100 msg ("DBG", fmt, args);
105 inline void ccunit_log (const char* fmt, ...)
107 if (_ccunit_verbose_message || _ccunit_debug_message)
110 va_start (args, fmt);
111 msg ("LOG", fmt, args);
116 inline void ccunit_err (const char* fmt, ...)
119 va_start (args, fmt);
120 msg ("ERR", fmt, args);
124 inline void ccunit_msg (const char* fmt, ...)
127 va_start (args, fmt);
128 msg ("CCUNIT", fmt, args);