author | herrick |
Fri, 08 Nov 2019 14:53:03 -0500 | |
branch | JDK-8200758-branch |
changeset 58994 | b09ba68c6a19 |
parent 57909 | src/jdk.jpackage/windows/native/libjpackage/Log.cpp@c7de06ed4b54 |
permissions | -rw-r--r-- |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
1 |
/* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
4 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
10 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
16 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
20 |
* |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
23 |
* questions. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
24 |
*/ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
25 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
26 |
#include "Log.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
27 |
#include "SysInfo.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
28 |
#include "FileUtils.h" |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
29 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
30 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
31 |
namespace { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
32 |
// |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
33 |
// IMPORTANT: Static objects with non-trivial constructors are NOT allowed |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
34 |
// in logger module. Allocate buffers only and do lazy initialization of |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
35 |
// globals in Logger::getDefault(). |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
36 |
// |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
37 |
// Logging subsystem is used almost in every module, and logging API can be |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
38 |
// called from constructors of static objects in various modules. As |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
39 |
// ordering of static objects initialization between modules is undefined, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
40 |
// this means some module may call logging api before logging static |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
41 |
// variables are initialized if any. This will result in AV. To avoid such |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
42 |
// use cases keep logging module free from static variables that require |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
43 |
// initialization with functions called by CRT. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
44 |
// |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
45 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
46 |
// by default log everything |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
47 |
const Logger::LogLevel defaultLogLevel = Logger::LOG_TRACE; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
48 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
49 |
char defaultLogAppenderMemory[sizeof(StderrLogAppender)] = {}; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
50 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
51 |
char defaultLoggerMemory[sizeof(Logger)] = {}; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
52 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
53 |
NopLogAppender nopLogApender; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
54 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
55 |
LPCTSTR getLogLevelStr(Logger::LogLevel level) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
56 |
switch (level) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
57 |
case Logger::LOG_TRACE: |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
58 |
return _T("TRACE"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
59 |
case Logger::LOG_INFO: |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
60 |
return _T("INFO"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
61 |
case Logger::LOG_WARNING: |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
62 |
return _T("WARNING"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
63 |
case Logger::LOG_ERROR: |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
64 |
return _T("ERROR"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
65 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
66 |
return _T("UNKNOWN"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
67 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
68 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
69 |
tstring retrieveModuleName() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
70 |
try { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
71 |
return FileUtils::basename(SysInfo::getCurrentModulePath()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
72 |
} catch (const std::exception&) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
73 |
return _T("Unknown"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
74 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
75 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
76 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
77 |
TCHAR moduleName[MAX_PATH] = { 'U', 'n', 'k', 'o', 'w', 'n', TCHAR(0) }; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
78 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
79 |
const LPCTSTR format = _T("[%04u/%02u/%02u %02u:%02u:%02u.%03u, %s (PID: %u, TID: %u), %s:%u (%s)]\n\t%s: %s\n"); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
80 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
81 |
enum State { NotInitialized, Initializing, Initialized }; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
82 |
State state = NotInitialized; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
83 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
84 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
85 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
86 |
LogEvent::LogEvent() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
87 |
memset(this, 0, sizeof(*this)); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
88 |
moduleName = tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
89 |
logLevel = tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
90 |
fileName = tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
91 |
funcName = tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
92 |
message = tstring(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
93 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
94 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
95 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
96 |
StderrLogAppender::StderrLogAppender() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
97 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
98 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
99 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
100 |
/*static*/ |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
101 |
Logger& Logger::defaultLogger() { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
102 |
Logger* reply = reinterpret_cast<Logger*>(defaultLoggerMemory); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
103 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
104 |
if (!reply->appender) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
105 |
// Memory leak by design. Not an issue at all as this is global |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
106 |
// object. OS will do resources clean up anyways when application |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
107 |
// terminates and the default log appender should live as long as |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
108 |
// application lives. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
109 |
reply->appender = new (defaultLogAppenderMemory) StderrLogAppender(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
110 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
111 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
112 |
if (Initializing == state) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
113 |
// Recursive call to Logger::defaultLogger. |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
114 |
moduleName[0] = TCHAR(0); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
115 |
} else if (NotInitialized == state) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
116 |
state = Initializing; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
117 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
118 |
tstring mname = retrieveModuleName(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
119 |
mname.resize(_countof(moduleName) - 1); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
120 |
std::memcpy(moduleName, mname.c_str(), mname.size()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
121 |
moduleName[mname.size()] = TCHAR(0); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
122 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
123 |
// if JPACKAGE_DEBUG environment variable is NOT set to "true" disable |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
124 |
// logging. |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
125 |
if (SysInfo::getEnvVariable(std::nothrow, |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
126 |
L"JPACKAGE_DEBUG") != L"true") { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
127 |
reply->appender = &nopLogApender; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
128 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
129 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
130 |
state = Initialized; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
131 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
132 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
133 |
return *reply; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
134 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
135 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
136 |
Logger::Logger(LogAppender& appender, LogLevel logLevel) |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
137 |
: level(logLevel), appender(&appender) { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
138 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
139 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
140 |
void Logger::setLogLevel(LogLevel logLevel) { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
141 |
level = logLevel; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
142 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
143 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
144 |
Logger::~Logger() { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
145 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
146 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
147 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
148 |
bool Logger::isLoggable(LogLevel logLevel) const { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
149 |
return logLevel >= level; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
150 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
151 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
152 |
void Logger::log(LogLevel logLevel, LPCTSTR fileName, int lineNum, |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
153 |
LPCTSTR funcName, const tstring& message) const { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
154 |
LogEvent logEvent; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
155 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
156 |
// [YYYY/MM/DD HH:MM:SS.ms, <module> (PID: processID, TID: threadID), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
157 |
// fileName:lineNum (funcName)] <tab>LEVEL: message |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
158 |
GetLocalTime(&logEvent.ts); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
159 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
160 |
logEvent.pid = GetCurrentProcessId(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
161 |
logEvent.tid = GetCurrentThreadId(); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
162 |
logEvent.moduleName = moduleName; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
163 |
logEvent.fileName = FileUtils::basename(fileName); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
164 |
logEvent.funcName = funcName; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
165 |
logEvent.logLevel = getLogLevelStr(logLevel); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
166 |
logEvent.lineNum = lineNum; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
167 |
logEvent.message = message; |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
168 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
169 |
appender->append(logEvent); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
170 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
171 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
172 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
173 |
void StderrLogAppender::append(const LogEvent& v) |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
174 |
{ |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
175 |
const tstring out = tstrings::unsafe_format(format, |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
176 |
unsigned(v.ts.wYear), unsigned(v.ts.wMonth), unsigned(v.ts.wDay), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
177 |
unsigned(v.ts.wHour), unsigned(v.ts.wMinute), unsigned(v.ts.wSecond), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
178 |
unsigned(v.ts.wMilliseconds), |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
179 |
v.moduleName.c_str(), v.pid, v.tid, |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
180 |
v.fileName.c_str(), v.lineNum, v.funcName.c_str(), |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
181 |
v.logLevel.c_str(), |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
182 |
v.message.c_str()); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
183 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
184 |
std::cerr << tstrings::toUtf8(out); |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
185 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
186 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
187 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
188 |
// Logger::ScopeTracer |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
189 |
Logger::ScopeTracer::ScopeTracer(Logger &logger, LogLevel logLevel, |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
190 |
LPCTSTR fileName, int lineNum, LPCTSTR funcName, |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
191 |
const tstring& scopeName) : log(logger), level(logLevel), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
192 |
file(fileName), line(lineNum), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
193 |
func(funcName), scope(scopeName), needLog(logger.isLoggable(logLevel)) { |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
194 |
if (needLog) { |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
195 |
log.log(level, file.c_str(), line, func.c_str(), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
196 |
tstrings::any() << "Entering " << scope); |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
197 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
198 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
199 |
|
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
200 |
Logger::ScopeTracer::~ScopeTracer() { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
201 |
if (needLog) { |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
202 |
// we don't know what line is end of scope at, so specify line 0 |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
203 |
// and add note about line when the scope begins |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
204 |
log.log(level, file.c_str(), 0, func.c_str(), |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
205 |
tstrings::any() << "Exiting " << scope << " (entered at " |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57413
diff
changeset
|
206 |
<< FileUtils::basename(file) << ":" << line << ")"); |
57413
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
207 |
} |
45c74e654794
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler (missed files)
herrick
parents:
diff
changeset
|
208 |
} |