~ubuntu-branches/ubuntu/oneiric/cairo-dock/oneiric

« back to all changes in this revision

Viewing changes to src/cairo-dock-log.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mto: (18.1.1 cairo-dock) (19.1.1 cairo-dock)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20100809232612-pocdxliaxjdetm37
Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** cairo-dock-log.c
3
 
** Login : <ctaf42@gmail.com>
4
 
** Started on  Sat Feb  9 15:54:57 2008 Cedric GESTES
5
 
** $Id$
6
 
**
7
 
** Author(s)
8
 
**  - Cedric GESTES
9
 
**
10
 
** Copyright (C) 2008 Cedric GESTES
11
 
** This program is free software; you can redistribute it and/or modify
12
 
** it under the terms of the GNU General Public License as published by
13
 
** the Free Software Foundation; either version 3 of the License, or
14
 
** (at your option) any later version.
15
 
**
16
 
** This program is distributed in the hope that it will be useful,
17
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
** GNU General Public License for more details.
20
 
**
21
 
** You should have received a copy of the GNU General Public License
22
 
** along with this program; if not, write to the Free Software
23
 
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
 
*/
25
 
 
26
 
#include <stdio.h>
27
 
#include <string.h>
28
 
#include <stdarg.h>
29
 
 
30
 
#include "cairo-dock-log.h"
31
 
 
32
 
static char s_iLogColor = '0';
33
 
static GLogLevelFlags s_gLogLevel = 0;
34
 
 
35
 
/* #    'default'     => "\033[1m", */
36
 
 
37
 
/* #    'black'     => "\033[30m", */
38
 
/* #    'red'       => "\033[31m", */
39
 
/* #    'green'     => "\033[32m", */
40
 
/* #    'yellow'    => "\033[33m", */
41
 
/* #    'blue'      => "\033[34m", */
42
 
/* #    'magenta'   => "\033[35m", */
43
 
/* #    'cyan'      => "\033[36m", */
44
 
/* #    'white'     => "\033[37m", */
45
 
 
46
 
 
47
 
const char*_cd_log_level_to_string(const GLogLevelFlags loglevel)
48
 
{
49
 
  switch(loglevel)
50
 
  {
51
 
  case G_LOG_LEVEL_CRITICAL:
52
 
    return "\033[1;31mCRITICAL: \033[0m ";
53
 
  case G_LOG_LEVEL_ERROR:
54
 
    return "\033[1;31mERROR   : \033[0m ";
55
 
  case G_LOG_LEVEL_WARNING:
56
 
    return "\033[1;38mwarning : \033[0m ";
57
 
  case G_LOG_LEVEL_MESSAGE:
58
 
    return "\033[1;32mmessage : \033[0m ";
59
 
  case G_LOG_LEVEL_INFO:
60
 
    return "\033[1;33minfo    : \033[0m ";
61
 
  case G_LOG_LEVEL_DEBUG:
62
 
    return "\033[1;35mdebug   : \033[0m ";
63
 
  }
64
 
  return "";
65
 
}
66
 
 
67
 
void cd_log_location(const GLogLevelFlags loglevel,
68
 
                     const char *file,
69
 
                     const char *func,
70
 
                     const int line,
71
 
                     const char *format,
72
 
                     ...)
73
 
{
74
 
  va_list args;
75
 
 
76
 
  if (loglevel > s_gLogLevel)
77
 
    return;
78
 
  g_print(_cd_log_level_to_string(loglevel));
79
 
  g_print("\033[0;37m(%s:%s:%d) \033[%cm \n  ", file, func, line, s_iLogColor);
80
 
  va_start(args, format);
81
 
  g_logv(G_LOG_DOMAIN, loglevel, format, args);
82
 
  va_end(args);
83
 
}
84
 
 
85
 
static void cairo_dock_log_handler(const gchar *log_domain,
86
 
                                   GLogLevelFlags log_level,
87
 
                                   const gchar *message,
88
 
                                   gpointer user_data)
89
 
{
90
 
  if (log_level > s_gLogLevel)
91
 
    return;
92
 
  g_print("%s\n", message);
93
 
}
94
 
 
95
 
void cd_log_init(gboolean bBlackTerminal)
96
 
{
97
 
  g_log_set_default_handler(cairo_dock_log_handler, NULL);
98
 
  s_iLogColor = (bBlackTerminal ? '1' : '0');
99
 
}
100
 
 
101
 
void cd_log_set_level(GLogLevelFlags loglevel)
102
 
{
103
 
  s_gLogLevel = loglevel;
104
 
}
105
 
 
106
 
 
107
 
void cd_log_set_level_from_name (const gchar *cVerbosity)
108
 
{
109
 
        if (!cVerbosity)
110
 
                cd_log_set_level(G_LOG_LEVEL_WARNING);
111
 
        else if (!strcmp(cVerbosity, "debug"))
112
 
                cd_log_set_level(G_LOG_LEVEL_DEBUG);
113
 
        else if (!strcmp(cVerbosity, "message"))
114
 
                cd_log_set_level(G_LOG_LEVEL_MESSAGE);
115
 
        else if (!strcmp(cVerbosity, "warning"))
116
 
                cd_log_set_level(G_LOG_LEVEL_WARNING);
117
 
        else if (!strcmp(cVerbosity, "critical"))
118
 
                cd_log_set_level(G_LOG_LEVEL_CRITICAL);
119
 
        else if (!strcmp(cVerbosity, "error"))
120
 
                cd_log_set_level(G_LOG_LEVEL_ERROR);
121
 
        else {
122
 
                cd_log_set_level(G_LOG_LEVEL_WARNING);
123
 
                cd_warning("bad verbosity option: default to warning");
124
 
        }
125
 
}