mirror of
https://github.com/gosticks/PiPer.git
synced 2026-07-01 13:50:01 +00:00
Added logging module
Added new logging module, removed old logging references, and added support to set logging level during build script
This commit is contained in:
19
make.sh
19
make.sh
@@ -25,6 +25,7 @@ Options:
|
||||
-c --compress-css Compress CSS
|
||||
-j --compress-js Compress JavaScript
|
||||
-s --compress-svg Compress SVG
|
||||
-l --logging-level <number> Set logging level (0=all 10=trace 20=info 30=warning 40=error)
|
||||
-e --package-extension Package extension for distribution (safari-legacy requires private key)
|
||||
-d --no-debug-js Remove JavaScript source maps to prevent debugging
|
||||
-v --no-version-increment Disable automatic version incrementing
|
||||
@@ -41,7 +42,7 @@ while :; do
|
||||
-h|-\?|--help) show_help ;;
|
||||
-p|--profile) [[ "$2" ]] && profile=$2 ;;
|
||||
--profile=?*) profile=${1#*=} ;;
|
||||
-t|--target) shift ;;
|
||||
-l|-t|--logging-level|--target) shift ;;
|
||||
-?*) ;;
|
||||
*) break
|
||||
esac
|
||||
@@ -56,6 +57,7 @@ case $profile in
|
||||
compress_js=1
|
||||
debug_js=0
|
||||
package_ext=1
|
||||
logging_level=100
|
||||
;;
|
||||
release)
|
||||
compress_svg=1
|
||||
@@ -63,6 +65,7 @@ case $profile in
|
||||
compress_js=1
|
||||
debug_js=1
|
||||
package_ext=0
|
||||
logging_level=40
|
||||
;;
|
||||
*)
|
||||
compress_svg=0
|
||||
@@ -70,6 +73,7 @@ case $profile in
|
||||
compress_js=0
|
||||
debug_js=1
|
||||
package_ext=0
|
||||
logging_level=0
|
||||
profile="debug"
|
||||
;;
|
||||
esac
|
||||
@@ -89,6 +93,8 @@ while :; do
|
||||
-v|--no-version-increment) update_version=0 ;;
|
||||
-t|--target) [[ "$2" ]] && targets=$2 && shift ;;
|
||||
--target=?*) targets=${1#*=} ;;
|
||||
-l|--logging-level) [[ "$2" ]] && logging_level=$2 && shift ;;
|
||||
--logging-level=?*) logging_level=${1#*=} ;;
|
||||
-p|--profile) shift ;;
|
||||
-?*) ;;
|
||||
*) break ;;
|
||||
@@ -315,8 +321,13 @@ for target in "${targets[@]}"; do
|
||||
|
||||
|
||||
scripts_path=$(get_absolute_path "out/${EXTENSION_NAME}-${target}${target_extension}${common_file_path}/scripts")
|
||||
defines_path="${scripts_path}/defines.js"
|
||||
extern_path=$(fix_absolute_path "${scripts_path}/externs.js")
|
||||
|
||||
defines_processed_path=$(echo "${defines_path%.*}" | sed -E 's|[/@\]|$|g' | sed -E 's/[-. ]/_/g' | sed -e 's/\[/%5B/g' -e 's/]/%5D/g' -e 's/>/%3E/g' -e 's/</%3C/g')
|
||||
logging_flag="LOGGING_LEVEL$\$module${defines_processed_path}=${logging_level}"
|
||||
|
||||
|
||||
for entry in "${SOURCE_FILES[@]}"; do
|
||||
files=()
|
||||
|
||||
@@ -333,6 +344,11 @@ for target in "${targets[@]}"; do
|
||||
for path in "${files[@]}"; do
|
||||
path=$(fix_absolute_path "$path")
|
||||
js_code=("--js" "$path" "${js_code[@]}")
|
||||
if [[ "$path" = "$defines_path" ]]; then
|
||||
defines=(
|
||||
"--define" "$logging_flag"
|
||||
)
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$debug_js" -eq 0 ]]; then
|
||||
@@ -363,6 +379,7 @@ for target in "${targets[@]}"; do
|
||||
--jscomp_error checkVars \
|
||||
--jscomp_error reportUnknownTypes \
|
||||
--externs "$extern_path" \
|
||||
"${defines[@]}" \
|
||||
)
|
||||
fi
|
||||
|
||||
|
||||
Binary file not shown.
2
src/common/scripts/defines.js
Normal file
2
src/common/scripts/defines.js
Normal file
@@ -0,0 +1,2 @@
|
||||
/** @define {number} - Flag used by closure compiler to set logging level */
|
||||
export const LOGGING_LEVEL = 0;
|
||||
36
src/common/scripts/logger.js
Normal file
36
src/common/scripts/logger.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { LOGGING_LEVEL } from './defines.js'
|
||||
|
||||
const loggingPrefix = '[PiPer] ';
|
||||
|
||||
/** @enum {number} - Enum for logging level */
|
||||
export const LoggingLevel = {
|
||||
ALL: 0,
|
||||
TRACE: 10,
|
||||
INFO: 20,
|
||||
WARNING: 30,
|
||||
ERROR: 40,
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs stack trace to console
|
||||
*/
|
||||
export const trace = (LoggingLevel.TRACE >= LOGGING_LEVEL) ?
|
||||
console.trace.bind(console) : function(){};
|
||||
|
||||
/**
|
||||
* Logs informational message to console
|
||||
*/
|
||||
export const info = (LoggingLevel.INFO >= LOGGING_LEVEL) ?
|
||||
console.info.bind(console, loggingPrefix) : function(){};
|
||||
|
||||
/**
|
||||
* Logs warning message to console
|
||||
*/
|
||||
export const warn = (LoggingLevel.WARNING >= LOGGING_LEVEL) ?
|
||||
console.warn.bind(console, loggingPrefix) : function(){};
|
||||
|
||||
/**
|
||||
* Logs error message to console
|
||||
*/
|
||||
export const error = (LoggingLevel.ERROR >= LOGGING_LEVEL) ?
|
||||
console.error.bind(console, loggingPrefix) : function(){};
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
import { info, error } from './logger.js'
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
@@ -18,9 +18,6 @@
|
||||
let PiperResource;
|
||||
|
||||
|
||||
/** @define {boolean} - Flag used by closure compiler to remove logging */
|
||||
const COMPILED = false;
|
||||
|
||||
const BUTTON_ID = 'PiPer_button';
|
||||
const TRACK_ID = 'PiPer_track';
|
||||
|
||||
@@ -31,15 +28,6 @@ let /** boolean */ showingCaptions = false;
|
||||
let /** boolean */ showingEmptyCaption = false;
|
||||
let /** string */ lastUnprocessedCaption = '';
|
||||
|
||||
/**
|
||||
* Logs message to console
|
||||
*
|
||||
* @param {string} message - Message to log
|
||||
*/
|
||||
const log = function(message) {
|
||||
!COMPILED && console.log('PiPer: ' + message);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns localized button title
|
||||
*
|
||||
@@ -100,7 +88,7 @@ const addButton = function(parent) {
|
||||
// Get the video element and bypass caching to accomodate for the underlying video changing (e.g. pre-roll adverts)
|
||||
const video = /** @type {?HTMLVideoElement} */ (currentResource.videoElement(true));
|
||||
if (!video) {
|
||||
log('Unable to find video');
|
||||
error('Unable to find video');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,7 +96,7 @@ const addButton = function(parent) {
|
||||
video.webkitSetPresentationMode(mode);
|
||||
});
|
||||
|
||||
log('Picture in Picture button created');
|
||||
info('Picture in Picture button created');
|
||||
}
|
||||
|
||||
// Inject button into correct place
|
||||
@@ -129,14 +117,14 @@ const prepareCaptions = function(video) {
|
||||
for (let trackId = allTracks.length; trackId--;) {
|
||||
if (allTracks[trackId].label === TRACK_ID) {
|
||||
track = allTracks[trackId];
|
||||
log('Existing caption track found');
|
||||
info('Existing caption track found');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (track) return;
|
||||
|
||||
// Otherwise create new caption track
|
||||
log('Caption track created');
|
||||
info('Caption track created');
|
||||
track = video.addTextTrack('captions', TRACK_ID, 'en');
|
||||
track.mode = 'showing';
|
||||
};
|
||||
@@ -159,7 +147,7 @@ const videoPresentationModeChanged = function(event) {
|
||||
lastUnprocessedCaption = '';
|
||||
processCaptions();
|
||||
|
||||
log('Video presentation mode changed (showingCaptions: ' + showingCaptions + ')');
|
||||
info('Video presentation mode changed (showingCaptions: ' + showingCaptions + ')');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -228,7 +216,7 @@ const processCaptions = function() {
|
||||
}
|
||||
}
|
||||
caption = caption.trim();
|
||||
log('Showing caption "' + caption + '"');
|
||||
info('Showing caption "' + caption + '"');
|
||||
track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, caption));
|
||||
showingEmptyCaption = false;
|
||||
};
|
||||
@@ -246,7 +234,7 @@ const mutationObserver = function() {
|
||||
if (buttonParent) {
|
||||
addButton(buttonParent);
|
||||
if (currentResource.buttonDidAppear) currentResource.buttonDidAppear();
|
||||
log('Picture in Picture button added to webpage');
|
||||
info('Picture in Picture button added to webpage');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1061,7 +1049,7 @@ resources['youtu'] = resources['youtube'];
|
||||
const domainName = location.hostname && location.hostname.match(/([^.]+)\.(?:co\.)?[^.]+$/)[1];
|
||||
|
||||
if (domainName in resources) {
|
||||
log('Matched site ' + domainName + ' (' + location + ')');
|
||||
info('Matched site ' + domainName + ' (' + location + ')');
|
||||
currentResource = resources[domainName];
|
||||
|
||||
initialiseCaches();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string></string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>160</string>
|
||||
<string>161</string>
|
||||
<key>Developer Identifier</key>
|
||||
<string>BQ6Q24MF9X</string>
|
||||
<key>URL</key>
|
||||
|
||||
Reference in New Issue
Block a user