3 This file is taken from nfsim (http://ozlabs.org/~jk/projects/nfsim/)
5 Copyright (c) 2003,2004 Jeremy Kerr & Rusty Russell
7 This file is part of nfsim.
9 nfsim 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 nfsim 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. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with nfsim; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 { LOG_WRITE, "write" },
38 { LOG_VERBOSE, "verbose" },
41 static int typemask = ~LOG_VERBOSE;
43 bool log_line(enum log_type type, const char *format, ...)
50 line = talloc_vasprintf(NULL, format, ap);
53 if (!type || (type & typemask)) {
58 ret = expect_log_hook(line);
63 static void log_partial_v(enum log_type type,
70 int len = strlen(buf);
72 /* write to the end of buffer */
73 if (vsnprintf(buf + len, bufsize - len - 1, format, ap)
74 > bufsize - len - 1) {
75 errx(1, "log_line_partial buffer is full!");
80 /* print each bit that ends in a newline */
81 for (len = strcspn(ptr, "\n"); *(ptr + len);
82 ptr += len, len = strcspn(ptr, "\n")) {
83 log_line(type, "%.*s", len++, ptr);
86 /* if we've printed, copy any remaining (non-newlined)
87 parts (including the \0) to the front of buf */
88 memmove(buf, ptr, strlen(ptr) + 1);
91 void log_partial(enum log_type type, char *buf, unsigned bufsize,
92 const char *format, ...)
97 log_partial_v(type, buf, bufsize, format, ap);
101 static inline int parsetype(const char *type)
105 for (i = 0; i < ARRAY_SIZE(log_names); i++)
106 if (streq(log_names[i].name, type))
107 return log_names[i].type;
112 static bool log_admin(int argc, char **argv)
118 log_line(LOG_UI, "current log types:", typemask);
120 for (i = 0; i < ARRAY_SIZE(log_names); i++) {
121 if (typemask & log_names[i].type)
122 log_line(LOG_UI, "\t%s", log_names[i].name);
128 log_line(LOG_ALWAYS, "Expected =, + or - then args");
132 for (i = 2; i < argc; i++) {
135 if (!(type = parsetype(argv[i]))) {
136 log_line(LOG_ALWAYS, "no such type %s", argv[i]);
144 typemask = newtypemask;
147 typemask &= ~newtypemask;
150 typemask |= newtypemask;
153 log_line(LOG_ALWAYS, "unknown modifer: %c", *argv[1]);
160 static void log_admin_help(int agc, char **argv)
162 #include "generated-log-help:log"
165 <title><command>log</command></title>
166 <para>Manage logging settings</para>
168 <command>log</command>
170 <arg choice="plain">=</arg>
171 <arg choice="plain">+</arg>
172 <arg choice="plain">-</arg>
174 <arg choice="req"><replaceable>type, ...</replaceable></arg>
176 <para>Each log message is classified into one of the following
181 <para>Normal response from command lines.</para>
187 <para>Logging output from libctdb</para>
194 <para>Messages from ctdbd</para>
200 <para>Messages to ctdbd</para>
206 <para>Verbose debug output</para>
211 <para>The <command>log</command> command allows you to select
212 which messages are displayed. By default, all messages except
213 debug will be shown.</para>
215 <para>Without any arguments, the current logged types are listed.</para>
217 <para>With +, - or = character, those types will be added,
218 removed or set as the current types of messages to be logged
219 (repectively).</para>
221 <para>Messages generated as a result of user input are always
222 logged. </para> </section>
226 static void log_init(void)
230 tui_register_command("log", log_admin, log_admin_help);