1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2015-2016 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#include "grn_report.h"
20
21const grn_log_level GRN_REPORT_INDEX_LOG_LEVEL = GRN_LOG_INFO;
22
23void
24grn_report_index(grn_ctx *ctx,
25 const char *action,
26 const char *tag,
27 grn_obj *index)
28{
29 char index_name[GRN_TABLE_MAX_KEY_SIZE];
30 int index_name_size;
31
32 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
33 return;
34 }
35
36 index_name_size = grn_obj_name(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZE);
37 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
38 "%s[index]%s <%.*s>",
39 action, tag, index_name_size, index_name);
40}
41
42void
43grn_report_index_not_used(grn_ctx *ctx,
44 const char *action,
45 const char *tag,
46 grn_obj *index,
47 const char *reason)
48{
49 char index_name[GRN_TABLE_MAX_KEY_SIZE];
50 int index_name_size;
51
52 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
53 return;
54 }
55
56 index_name_size = grn_obj_name(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZE);
57 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
58 "%s[index-not-used]%s <%.*s>: %s",
59 action, tag, index_name_size, index_name, reason);
60}
61
62void
63grn_report_table(grn_ctx *ctx,
64 const char *action,
65 const char *tag,
66 grn_obj *table)
67{
68 grn_obj description;
69 grn_obj *target;
70
71 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
72 return;
73 }
74
75 GRN_TEXT_INIT(&description, 0);
76 for (target = table; target; target = grn_ctx_at(ctx, target->header.domain)) {
77 char name[GRN_TABLE_MAX_KEY_SIZE];
78 int name_size;
79
80 name_size = grn_obj_name(ctx, target, name, GRN_TABLE_MAX_KEY_SIZE);
81 if (GRN_TEXT_LEN(&description) > 0) {
82 GRN_TEXT_PUTS(ctx, &description, " -> ");
83 }
84 if (name_size == 0) {
85 GRN_TEXT_PUTS(ctx, &description, "(temporary)");
86 } else {
87 GRN_TEXT_PUTS(ctx, &description, "<");
88 GRN_TEXT_PUT(ctx, &description, name, name_size);
89 GRN_TEXT_PUTS(ctx, &description, ">");
90 }
91 }
92 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
93 "%s[table]%s %.*s",
94 action, tag,
95 (int)GRN_TEXT_LEN(&description),
96 GRN_TEXT_VALUE(&description));
97 GRN_OBJ_FIN(ctx, &description);
98}
99