~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to libs/geis-util/geis_logging.c

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file geis_logging.h
 
3
 *
 
4
 * Copyright 2010 Canonical Ltd.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or modify it under
 
7
 * the terms of the GNU Lesser General Public License as published by the Free
 
8
 * Software Foundation; either version 3 of the License, or (at your option) any
 
9
 * later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 
14
 * details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
18
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
19
 */
 
20
#include "geis_logging.h"
 
21
 
 
22
#include <stdarg.h>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
 
 
27
 
 
28
static const char *prefix_format  = "GEIS(%s)-%s:%d ";
 
29
static const char *debug_marker   = "debug";
 
30
static const char *warning_marker = "warning";
 
31
static const char *error_marker   = "error";
 
32
 
 
33
 
 
34
static int
 
35
reporting_level()
 
36
{
 
37
  char *level = getenv("GEIS_DEBUG");
 
38
  if (level)
 
39
  {
 
40
    return atoi(level);
 
41
  }
 
42
  return 0;
 
43
}
 
44
 
 
45
static int
 
46
level_is_enabled(int desired_level)
 
47
{
 
48
  static int level = -1;
 
49
  if (level < 0)
 
50
    level = reporting_level();
 
51
  return level >= desired_level;
 
52
}
 
53
 
 
54
 
 
55
int
 
56
_geis_message(int level, const char* function, int line, const char *format, ...)
 
57
{
 
58
  int count = 0;
 
59
  if (level_is_enabled(level))
 
60
  {
 
61
    const char *marker = NULL;
 
62
    switch (level)
 
63
    {
 
64
      case _GEIS_LOG_LEVEL_DEBUG:
 
65
        marker = debug_marker;
 
66
        break;
 
67
      case _GEIS_LOG_LEVEL_WARNING:
 
68
        marker = warning_marker;
 
69
        break;
 
70
      default:
 
71
        marker = error_marker;
 
72
        break;
 
73
    }
 
74
 
 
75
    fprintf(stderr, prefix_format, marker, function, line);
 
76
 
 
77
    va_list ap;
 
78
    va_start(ap, format);
 
79
    count = vfprintf(stderr, format, ap);
 
80
    va_end(ap);
 
81
 
 
82
    fprintf(stderr, "\n");
 
83
  }
 
84
  return count;
 
85
}
 
86
 
 
87