source: branches/client-1.5/src/debug.c@ 188

Last change on this file since 188 was 188, checked in by Herwig Bauernfeind, 16 years ago

Fix for Ticket #88

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/*
2 Netdrive Samba client plugin
3 logging functions
4 Copyright (C) netlabs.org 2003-2009
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#define INCL_DOSERRORS
22#define INCL_DOS
23#include <os2emx.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <stdarg.h>
27#include <string.h>
28#include <sys/types.h>
29#include <sys/time.h>
30
31// #include "smbwrp.h"
32
33int debuglevel = 0;
34char *logfile = NULL;
35
36
37void dbgfileinit(char *file, int loglevel)
38{
39 logfile = file;
40 debuglevel = loglevel;
41}
42
43int debuglvl(int level)
44{
45 return (level <= debuglevel) ? 1 : 0;
46}
47
48int debugheader(int level, char * file, char * func, int line)
49{
50 int rc;
51 if (!debuglvl(level))
52 {
53 return 0;
54 }
55 rc = 1;
56 do
57 {
58 FILE * f;
59 struct timeval tv;
60 time_t t;
61 char buf[80] = {0};
62 if (logfile)
63 {
64 f = fopen(logfile, "a");
65 if (!f)
66 {
67 rc = 0;
68 break;
69 }
70 }
71 else
72 {
73 f = stdout;
74 }
75 gettimeofday(&tv, NULL);
76 t = time(NULL);
77 strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime(&t));
78 fprintf(f, "%s.%d: %d %d: %s:%s(%d) :", buf, tv.tv_usec / 10000, level, (long)_gettid(), file, func, line);
79 if (logfile)
80 {
81 fclose(f);
82 }
83 }
84 while (0);
85 return rc;
86}
87
88int debugmessage(char * fmt, ...)
89{
90 do
91 {
92 FILE * f;
93 va_list args;
94 if (logfile)
95 {
96 f = fopen(logfile, "a");
97 if (!f)
98 {
99 break;
100 }
101 }
102 else
103 {
104 f = stdout;
105 }
106 va_start(args, fmt);
107 vfprintf(f, fmt, args);
108 va_end(args);
109 if (logfile)
110 {
111 fclose(f);
112 }
113 }
114 while (0);
115 return 0;
116}
117
118void debuglocal(int level, const char * fmt, ...)
119{
120
121 if (!debuglvl(level))
122 {
123 return;
124 }
125 do
126 {
127 FILE * f;
128 struct timeval tv;
129 char buf[80] = {0};
130 va_list args;
131 if (logfile)
132 {
133 f = fopen(logfile, "a");
134 if (!f)
135 {
136 break;
137 }
138 }
139 else
140 {
141 f = stdout;
142 }
143 gettimeofday(&tv, NULL);
144 strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
145 fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
146 va_start(args, fmt);
147 vfprintf(f, fmt, args);
148 va_end(args);
149 if (logfile)
150 {
151 fclose(f);
152 }
153 }
154 while (0);
155}
Note: See TracBrowser for help on using the repository browser.