Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / onlineupdate / source / update / common / updatelogging.cxx
blobed055cd47072185783608aecf58ca9970e005dad
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #if defined(_WIN32)
6 #include <windows.h>
7 #endif
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
15 #include "updatelogging.h"
17 UpdateLog::UpdateLog()
18 : logFP(nullptr)
19 , sourcePath(nullptr)
23 void UpdateLog::Init(NS_tchar* sourcePathParam,
24 const NS_tchar* fileName,
25 const NS_tchar* alternateFileName,
26 bool append)
28 if (logFP)
29 return;
31 sourcePath = sourcePathParam;
32 NS_tchar logFile[MAXPATHLEN];
33 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
34 NS_T("%s/%s"), sourcePathParam, fileName);
36 if (alternateFileName && NS_taccess(logFile, F_OK))
38 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
39 NS_T("%s/%s"), sourcePathParam, alternateFileName);
42 logFP = NS_tfopen(logFile, append ? NS_T("a") : NS_T("w"));
45 void UpdateLog::Finish()
47 if (!logFP)
48 return;
50 fclose(logFP);
51 logFP = nullptr;
54 void UpdateLog::Flush()
56 if (!logFP)
57 return;
59 fflush(logFP);
62 void UpdateLog::Printf(const char *fmt, ... )
64 if (!logFP)
65 return;
67 va_list ap;
68 va_start(ap, fmt);
69 vfprintf(logFP, fmt, ap);
70 fprintf(logFP, "\n");
71 va_end(ap);
74 void UpdateLog::WarnPrintf(const char *fmt, ... )
76 if (!logFP)
77 return;
79 va_list ap;
80 va_start(ap, fmt);
81 fprintf(logFP, "*** Warning: ");
82 vfprintf(logFP, fmt, ap);
83 fprintf(logFP, "***\n");
84 va_end(ap);