source: trunk/client/src/debug.c@ 508

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

samba client 2.1: read fixes, more caching

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