/* Netdrive Samba client plugin logging functions Copyright (C) netlabs.org 2003-2009 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define INCL_DOSERRORS #define INCL_DOS #include #include #include #include #include #include #include #include int debuglevel = 9; // we set it to 9, so we get all messages char logfile[_MAX_PATH +1] = {0}; char debugfile[_MAX_PATH +1] = {0}; char logfilename[] = "ndpsmb.log"; int debuglvl(int level) { return (level <= debuglevel) ? 1 : 0; } void debuglocal(int level, const char * fmt, ...) { FILE *f=NULL; struct stat filestat; // if the file ndpsmb.dbg is around we write a logfile if (!debugfile[0]) { strncpy(debugfile, getenv("ETC"), 2); strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1); strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1); } /* endif */ if (stat(debugfile, &filestat) !=0) return; //we create the logfile variable only once if (!logfile[0]) { char *env = getenv("LOGFILES"); if (env != NULL) { strncpy(logfile, env, sizeof(logfile) -1); strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1); strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); } else { strncpy(logfile, logfilename, sizeof(logfile) -1); } // set the samba logging stuff smbwrp_Logging(); } /* endif */ if (!debuglvl(level)) { return; } do { struct timeval tv; char buf[80] = {0}; va_list args; if (logfile[0]) { f = fopen(logfile, "a"); if (!f) { break; } } else { f = stdout; } gettimeofday(&tv, NULL); strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec)); fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid()); va_start(args, fmt); vfprintf(f, fmt, args); va_end(args); if (logfile) { fclose(f); } } while (0); }