Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 8fa2162

Browse files
committed
implement a basic logging mechanism using syslog
log data from `syslog` command can be easily accessed with the `Console.app` utility by searching for *syslog*
1 parent 5fa886b commit 8fa2162

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ Supported PList keys
162162

163163

164164

165+
Logging
166+
-------
167+
168+
Starting with version 2.2.0 `universalJavaApplicationStub` logs data to the `syslog` which can be easily accessed with the `Console.app` utility by searching for *syslog*:
169+
170+
![Example log data in Console.app](/docs/ConsoleAppLogging.png?raw=true)
171+
172+
173+
165174
Missing Features
166175
----------------
167176

docs/ConsoleAppLogging.png

229 KB
Loading

src/universalJavaApplicationStub

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# #
1414
# @author Tobias Fischer #
1515
# @url https://github.com/tofi86/universalJavaApplicationStub #
16-
# @date 2017-10-28 #
16+
# @date 2017-10-29 #
1717
# @version 2.1.0 #
1818
# #
1919
# #
@@ -46,6 +46,19 @@
4646

4747

4848

49+
# helper function:
50+
# A logger which logs to the macOS Console.app
51+
################################################
52+
function stubLogger() {
53+
syslog -s -k \
54+
Facility com.apple.console \
55+
Level Notice \
56+
Sender "$(basename "$0")" \
57+
Message "[$$][${CFBundleName:-$(basename "$0")}] $1"
58+
}
59+
60+
61+
4962
#
5063
# set the directory abspath of the current
5164
# shell script with symlinks being resolved
@@ -62,6 +75,7 @@ while [ -h "$PRG" ]; do
6275
fi
6376
done
6477
PROGDIR=`dirname "$PRG"`
78+
stubLogger "[StubDir] $PROGDIR"
6579

6680

6781

@@ -123,6 +137,7 @@ fi
123137

124138
# read Info.plist in Apple style if exit code returns 0 (true, :Java key is present)
125139
if [ $exitcode -eq 0 ]; then
140+
stubLogger "[PlistStyle] Apple"
126141

127142
# set Java and Resources folder
128143
JavaFolder="${AppleJavaFolder}"
@@ -193,6 +208,7 @@ if [ $exitcode -eq 0 ]; then
193208

194209
# read Info.plist in Oracle style
195210
else
211+
stubLogger "[PlistStyle] Oracle"
196212

197213
# set Working Directory and Java and Resources folder
198214
JavaFolder="${OracleJavaFolder}"
@@ -247,6 +263,7 @@ fi
247263
############################################
248264

249265
LANG=`defaults read -g AppleLocale`
266+
stubLogger "[Language] $LANG"
250267

251268
# French localization
252269
if [[ $LANG == fr* ]] ; then
@@ -387,6 +404,7 @@ oracle_jre_version=$(extractJavaMajorVersion $(extractJavaVersionString "${oracl
387404

388405
# first check system variable "$JAVA_HOME"
389406
if [ -n "$JAVA_HOME" ] ; then
407+
stubLogger '[JavaSearch] Checking $JAVA_HOME'
390408

391409
# PR 26: Allow specifying "$JAVA_HOME" relative to "$AppPackageFolder"
392410
# which allows for bundling a custom version of Java inside your app!
@@ -400,6 +418,7 @@ if [ -n "$JAVA_HOME" ] ; then
400418

401419
# check for a specific Java version, specified in JVMversion Plist key
402420
elif [ ! -z ${JVMVersion} ] ; then
421+
stubLogger "[JavaSearch] Checking for specific Java version '${JVMVersion}'"
403422

404423
# first check "/usr/libexec/java_home" symlinks
405424
if [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F -v ${JVMVersion} > /dev/null 2>&1 ; then
@@ -430,6 +449,8 @@ elif [ ! -z ${JVMVersion} ] ; then
430449
if [ -z "${JAVACMD}" ] ; then
431450
# display human readable java version (#28)
432451
java_version_hr=`echo ${JVMVersion} | sed -E 's/[0-9]\.([0-9+*]+)/ \1/g' | sed "s/+/ ${MSG_JAVA_VERSION_OR_LATER}/" | sed "s/*/ ${MSG_JAVA_VERSION_LATEST}/"`
452+
# log exit cause
453+
stubLogger "[EXIT 3] ${MSG_NO_SUITABLE_JAVA}${java_version_hr}"
433454
# display error message with applescript
434455
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_NO_SUITABLE_JAVA}${java_version_hr}.\n${MSG_NO_SUITABLE_JAVA_CHECK}\" with title \"${CFBundleName}\" buttons {\" OK \", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \
435456
-e "set response to button returned of the result" \
@@ -440,6 +461,7 @@ elif [ ! -z ${JVMVersion} ] ; then
440461

441462
# otherwise check "/usr/libexec/java_home" and Oracle and Apple JRE paths and use highest version available
442463
else
464+
stubLogger "[JavaSearch] Checking for other Java versions"
443465

444466
# first check "/usr/libexec/java_home" symlinks
445467
if [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F > /dev/null 2>&1 ; then
@@ -468,6 +490,10 @@ else
468490
fi
469491
fi
470492

493+
# log the Java Command and the extracted version number
494+
stubLogger "[JavaCommand] $JAVACMD"
495+
stubLogger "[JavaVersion] $(extractJavaVersionString "${JAVACMD}")${JAVACMD_version:+ / $JAVACMD_version}"
496+
471497
# fallback fallback: /usr/bin/java
472498
# but this would prompt to install deprecated Apple Java 6
473499

@@ -479,6 +505,8 @@ fi
479505

480506
# display error message if MainClassName is empty
481507
if [ -z ${JVMMainClass} ]; then
508+
# log exit cause
509+
stubLogger "[EXIT 2] ${MSG_MISSING_MAINCLASS}"
482510
# display error message with applescript
483511
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_MISSING_MAINCLASS}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
484512
# exit with error
@@ -500,6 +528,7 @@ elif [ -f "${JAVACMD}" ] && [ -x "${JAVACMD}" ] ; then
500528

501529
# change to Working Directory based upon Apple/Oracle Plist info
502530
cd "${WorkingDirectory}"
531+
stubLogger "[WorkingDirectory] ${WorkingDirectory}"
503532

504533
# execute Java and set
505534
# - classpath
@@ -511,6 +540,7 @@ elif [ -f "${JAVACMD}" ] && [ -x "${JAVACMD}" ] ; then
511540
# - main class
512541
# - main arguments
513542
# - passthru arguments
543+
stubLogger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptions:+$JVMOptions }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgs:+ $MainArgs}${ArgsPassthru:+ $ArgsPassthru}"
514544
exec "${JAVACMD}" \
515545
-cp "${JVMClassPath}" \
516546
-splash:"${ResourcesFolder}/${JVMSplashFile}" \
@@ -524,6 +554,8 @@ elif [ -f "${JAVACMD}" ] && [ -x "${JAVACMD}" ] ; then
524554

525555

526556
else
557+
# log exit cause
558+
stubLogger "[EXIT 1] ${MSG_ERROR_LAUNCHING}"
527559
# display error message with applescript
528560
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \
529561
-e "set response to button returned of the result" \

0 commit comments

Comments
 (0)