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

Last change on this file since 436 was 436, checked in by Silvan Scherrer, 15 years ago

client 1.5: samba logging part 2

  • Property svn:eol-style set to native
File size: 3.0 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#include <sys/stat.h>
31
32int debuglevel = 9; // we set it to 9, so we get all messages
33char logfile[_MAX_PATH +1] = {0};
34char debugfile[_MAX_PATH +1] = {0};
35char logfilename[] = "ndpsmb.log";
36BOOL do_logging;
37
38int debuglvl(int level)
39{
40 return (level <= debuglevel) ? 1 : 0;
41}
42
43BOOL writeLog()
44{
45 return do_logging;
46}
47
48void debuglocal(int level, const char * fmt, ...)
49{
50 FILE *f=NULL;
51 struct stat filestat;
52 do_logging = FALSE;
53
54 // if the file ndpsmb.dbg is around we write a logfile
55 if (!debugfile[0])
56 {
57 strncpy(debugfile, getenv("ETC"), 2);
58 strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
59 strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
60 } /* endif */
61
62 if (stat(debugfile, &filestat) !=0)
63 return;
64
65 //we create the logfile variable only once
66 if (!logfile[0])
67 {
68 char *env = getenv("LOGFILES");
69 if (env != NULL)
70 {
71 strncpy(logfile, env, sizeof(logfile) -1);
72 strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
73 strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1);
74 }
75 else
76 {
77 strncpy(logfile, logfilename, sizeof(logfile) -1);
78 }
79 // set the samba logging stuff
80 do_logging = TRUE;
81 } /* endif */
82
83 if (!debuglvl(level))
84 {
85 return;
86 }
87 do
88 {
89 struct timeval tv;
90 char buf[80] = {0};
91 va_list args;
92 if (logfile[0])
93 {
94 f = fopen(logfile, "a");
95 if (!f)
96 {
97 break;
98 }
99 }
100 else
101 {
102 f = stdout;
103 }
104 gettimeofday(&tv, NULL);
105 strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
106 fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
107 va_start(args, fmt);
108 vfprintf(f, fmt, args);
109 va_end(args);
110 if (logfile)
111 {
112 fclose(f);
113 }
114 }
115 while (0);
116}
Note: See TracBrowser for help on using the repository browser.