Skip to content

Commit 9f6fa33

Browse files
committed
unified logging of Perl scripts and JavaScript in the JavaScript console
1 parent 4fa2d5e commit 9f6fa33

File tree

11 files changed

+102
-191
lines changed

11 files changed

+102
-191
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ build-peb-*/
33
perl/bin
44
perl/lib
55
src/tmp
6-
resources/logs/
76

87
*.autosave
98
Makefile

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ https://superuser.com/questions/188058/which-ports-are-considered-unsafe-on-chro
241241
https://github.com/github/linguist#overrides
242242

243243
## Travis CI
244+
https://docs.travis-ci.com/user/reference/xenial/
244245
https://stackoverflow.com/questions/25737062/travis-ci-for-a-qt5-project
245246

246247
## AppImage

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Perl Executing Browser (PEB) is an HTML5 user interface for [Perl 5](https://www
3535
* [PACKAGING](./doc/PACKAGING.md)
3636
* [Minimal Relocatable Perl Distribution for PEB](./doc/PACKAGING.md#minimal-relocatable-perl-distribution-for-peb)
3737
* [AppImage Support](./doc/PACKAGING.md#appimage-support)
38+
* [DEBUGGING](./doc/DEBUGGING.md)
3839
* [History](#history)
3940
* [License](./LICENSE.md)
4041
* [Thanks and Credits](./doc/CREDITS.md)
@@ -82,10 +83,10 @@ These are the basic steps for building your first PEB-based application using a
8283
* [Perl local servers can be started.](./doc/SETTINGS.md#starting-local-server)
8384
* [Any version of Perl 5 can be used.](./doc/REQUIREMENTS.md#runtime-requirements)
8485
* [Single file or multiple files, new filename, existing or new directory can be selected by user.](./doc/SETTINGS.md#selecting-files-and-folders)
85-
* [Custom labels for all JavaScript popup boxes and context menus](./doc/SETTINGS.md#html-page-api)
86-
* [Custom icon for the main window and all dialog boxes](./doc/CONSTANTS.md#icon)
86+
* Unified logging of Perl scripts and JavaScript in the JavaScript console
87+
* [Optional labels for all JavaScript popup boxes and context menus](./doc/SETTINGS.md#html-page-api)
88+
* [Optional icon for the main window and all dialog boxes](./doc/CONSTANTS.md#icon)
8789
* [Optional warning for unsaved data in HTML forms](./doc/SETTINGS.md#html-page-api)
88-
* [Optional Perl scripts error logging](./doc/CONSTANTS.md#log-files-directory)
8990

9091
## Security
9192
* PEB does not need administrative privileges, but will not refuse to use them if needed.

doc/CONSTANTS.md

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,53 @@ A typical ``{PEB_executable_directory}`` looks like this:
3030
The ``bin`` subdirectory must contain the Perl interpreter.
3131
The ``lib`` subdirectory must contain all Perl modules used by PEB Perl applications.
3232

33-
* **Perl Interpreter:**
34-
Relocatable Perl interpreter, if present, must be located in the ``{PEB_executable_directory}/perl/bin`` folder.
35-
The Perl interpreter must be named ``perl`` on Linux and Mac machines and ``wperl.exe`` on Windows machines.
36-
If a relocatable Perl interpreter is not found, PEB will use the first Perl interpreter on PATH.
33+
* **Perl Interpreter:**
34+
Relocatable Perl interpreter, if present, must be located in the ``{PEB_executable_directory}/perl/bin`` folder.
35+
The Perl interpreter must be named ``perl`` on Linux and Mac machines and ``wperl.exe`` on Windows machines.
36+
If a relocatable Perl interpreter is not found, PEB will use the first Perl interpreter on PATH.
3737

38-
* **Perl Modules Directory:**
39-
All Perl modules found in the ``{PEB_executable_directory}/perl/lib`` folder are accessible via the ``PERL5LIB`` environment variable for all Perl applications executed by PEB.
38+
* **Perl Modules Directory:**
39+
All Perl modules found in the ``{PEB_executable_directory}/perl/lib`` folder are accessible via the ``PERL5LIB`` environment variable for all Perl applications executed by PEB.
4040

4141
* **Resources Directory:**
4242
The resources directory must contain the ``app`` subdirectory with all necessary application files.
43-
``data`` and ``logs`` subdirectories are optional, as well as the application icon file: ``app.png``
43+
``data`` subdirectory and the application icon file ``app.png`` are optional.
4444
The resources directory path must be: ``{PEB_executable_directory}/resources``
4545

46-
* **Application Directory:**
47-
All Perl application files must be located within this folder.
48-
The application directory path must be: ``{PEB_executable_directory}/resources/app``
49-
PEB application directory is labeled as ``{PEB_app_directory}`` within this documentation.
50-
By default the working directory of all Perl scripts run by PEB is the application directory.
51-
52-
PEB application directory pathname is compatible with the [Electron](http://electron.atom.io/) framework.
53-
[Epigraphista](https://github.com/ddmitov/epigraphista) is an application which is runnable by both PEB and [Electron](http://electron.atom.io/).
54-
55-
* **Start File:**
56-
PEB starts with one of the following files:
57-
* ``{PEB_executable_directory}/resources/app/index.html``
58-
* ``{PEB_executable_directory}/resources/app/local-server.json``
59-
60-
If both files are present, ``index.html`` takes precedence.
61-
If ``index.html`` is missing, ``local-server.json`` is used if available.
62-
If both entry files are missing, an error message is displayed.
63-
64-
<a name="icon"></a>
65-
* **Icon:**
66-
A PEB-based application may have its own icon and the pathname must be:
67-
``{PEB_executable_directory}/resources/app.png``
68-
69-
If this file is found during application startup, it is used as the icon of the application and all dialog boxes.
70-
If this file is not found, the default icon embedded in the resources of the browser binary is used.
71-
72-
* **Data Directory:**
73-
Data directory may contain any writable files used or produced by a PEB-based application.
74-
The data directory path must be: ``{PEB_executable_directory}/resources/data``
75-
Perl scripts can access this folder using the environment variable ``PEB_DATA_DIR``:
76-
77-
```perl
78-
my $data_directory = $ENV{'PEB_DATA_DIR'};
79-
```
80-
<a name="log-files-directory"></a>
81-
* **Log Files Directory:**
82-
When log files directory is found during application startup, PEB assumes that logging is required and a separate log file is created for every browser session following the naming convention:
83-
``{executable_name}-started-at-{four_digit_year}-{month}-{day}--{hour}-{minute}-{second}.log``
84-
85-
The log files directory path must be: ``{PEB_executable_directory}/resources/logs``
86-
PEB will not create log files directory on its own and if it is missing, no logs will be written.
46+
* **Application Directory:**
47+
All Perl application files must be located within this folder.
48+
The application directory path must be: ``{PEB_executable_directory}/resources/app``
49+
PEB application directory is labeled as ``{PEB_app_directory}`` within this documentation.
50+
By default the working directory of all Perl scripts run by PEB is the application directory.
51+
52+
PEB application directory pathname is compatible with the [Electron](http://electron.atom.io/) framework.
53+
[Epigraphista](https://github.com/ddmitov/epigraphista) is an application which is runnable by both PEB and [Electron](http://electron.atom.io/).
54+
55+
* **Start File:**
56+
PEB starts with one of the following files:
57+
* ``{PEB_executable_directory}/resources/app/index.html``
58+
* ``{PEB_executable_directory}/resources/app/local-server.json``
59+
60+
If both files are present, ``index.html`` takes precedence.
61+
If ``index.html`` is missing, ``local-server.json`` is used if available.
62+
If both entry files are missing, an error message is displayed.
63+
64+
<a name="icon"></a>
65+
* **Icon:**
66+
A PEB-based application may have its own icon and the pathname must be:
67+
``{PEB_executable_directory}/resources/app.png``
68+
69+
If this file is found during application startup, it is used as the icon of the application and all dialog boxes.
70+
If this file is not found, the default icon embedded in the resources of the browser binary is used.
71+
72+
* **Data Directory:**
73+
Data directory may contain any writable files used or produced by a PEB-based application.
74+
The data directory path must be: ``{PEB_executable_directory}/resources/data``
75+
Perl scripts can access this folder using the environment variable ``PEB_DATA_DIR``:
76+
77+
```perl
78+
my $data_directory = $ENV{'PEB_DATA_DIR'};
79+
```
8780

8881
## Functional Pseudo Filenames
8982
* **About PEB dialog:** ``about-browser.function``

src/main.cpp

Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717

1818
#include <QtWidgets/QApplication>
19-
#include <QDateTime>
20-
#include <QDebug>
2119
#include <QTextCodec>
2220
#include <QtGlobal>
2321

@@ -37,54 +35,6 @@
3735
#endif
3836
#endif
3937

40-
// ==============================
41-
// MESSAGE HANDLER FOR REDIRECTING
42-
// PROGRAM MESSAGES TO A LOG FILE:
43-
// ==============================
44-
// Implementation of an idea proposed by Valcho Nedelchev.
45-
void customMessageHandler(QtMsgType type,
46-
const QMessageLogContext &context,
47-
const QString &message)
48-
{
49-
Q_UNUSED(context);
50-
QString dateAndTime =
51-
QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
52-
QString text = QString("[%1] ").arg(dateAndTime);
53-
54-
switch (type) {
55-
#if QT_VERSION >= 0x050500
56-
case QtInfoMsg:
57-
text += QString("{Log} %1").arg(message);
58-
break;
59-
#endif
60-
case QtDebugMsg:
61-
text += QString("{Log} %1").arg(message);
62-
break;
63-
case QtWarningMsg:
64-
text += QString("{Warning} %1").arg(message);
65-
break;
66-
case QtCriticalMsg:
67-
text += QString("{Critical} %1").arg(message);
68-
break;
69-
case QtFatalMsg:
70-
text += QString("{Fatal} %1").arg(message);
71-
abort();
72-
break;
73-
}
74-
75-
// A separate log file is created for every browser session.
76-
// Application start date and time are appended to the binary file name.
77-
QFile logFile(qApp->property("logDirFullPath").toString()
78-
+ "/"
79-
+ QFileInfo(QApplication::applicationFilePath()).baseName()
80-
+ "-started-at-"
81-
+ qApp->property("applicationStartDateAndTime").toString()
82-
+ ".log");
83-
logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
84-
QTextStream textStream(&logFile);
85-
textStream << text << endl;
86-
}
87-
8838
// ==============================
8939
// MAIN APPLICATION DEFINITION:
9040
// ==============================
@@ -238,40 +188,19 @@ int main(int argc, char **argv)
238188
QApplication::setWindowIcon(icon);
239189
}
240190

241-
// ==============================
242-
// Logging:
243-
// ==============================
244-
// If 'logs' directory is found in the resources directory,
245-
// all program messages will be redirected to log files,
246-
// otherwise no log files will be created and
247-
// program messages may be seen inside Qt Creator during development.
248-
249-
QString logDirFullPath = resourcesDirectory + "/logs";
250-
251-
QDir logDir(logDirFullPath);
252-
if (logDir.exists()) {
253-
application.setProperty("logDirFullPath", logDirFullPath);
254-
255-
// Application start date and time for logging:
256-
QString applicationStartDateAndTime =
257-
QDateTime::currentDateTime().toString("yyyy-MM-dd--hh-mm-ss");
258-
application.setProperty("applicationStartDateAndTime",
259-
applicationStartDateAndTime);
260-
261-
// Install message handler for redirecting all messages to a log file:
262-
qInstallMessageHandler(customMessageHandler);
263-
}
264-
265191
// ==============================
266192
// MAIN WINDOW INITIALIZATION:
267193
// ==============================
268194
QMainBrowserWindow mainWindow;
195+
mainWindow.setWindowIcon(icon);
196+
mainWindow.setCentralWidget(mainWindow.webViewWidget);
269197

270-
// Application property necessary when
271-
// closing the browser window is requested using
272-
// the special window closing URL.
198+
// Application property used when closing the browser window is requested:
273199
qApp->setProperty("windowCloseRequested", false);
274200

201+
// ==============================
202+
// Signals and slots:
203+
// ==============================
275204
// Signal and slot for setting the main window title:
276205
QObject::connect(mainWindow.webViewWidget,
277206
SIGNAL(titleChanged(QString)),
@@ -298,20 +227,6 @@ int main(int argc, char **argv)
298227
QObject::connect(qApp, SIGNAL(aboutToQuit()),
299228
&mainWindow, SLOT(qExitApplicationSlot()));
300229

301-
// ==============================
302-
// Basic program information:
303-
// ==============================
304-
qDebug() << "Application version:"
305-
<< application.applicationVersion().toLatin1().constData();
306-
qDebug() << "Qt version:" << QT_VERSION_STR;
307-
qDebug() << "Perl interpreter:" << perlInterpreter;
308-
309-
// ==============================
310-
// Window initialization:
311-
// ==============================
312-
mainWindow.setWindowIcon(icon);
313-
mainWindow.setCentralWidget(mainWindow.webViewWidget);
314-
315230
// ==============================
316231
// Start file:
317232
// ==============================
@@ -374,7 +289,6 @@ int main(int argc, char **argv)
374289
} else {
375290
mainWindow.qDisplayError(
376291
QString("Local server file is not found."));
377-
qDebug() << "Local server file is not found.";
378292
}
379293

380294
// Local server port:
@@ -387,7 +301,6 @@ int main(int argc, char **argv)
387301
localServerSettingsCorrect = false;
388302
mainWindow.qDisplayError(
389303
QString("No local server port is set."));
390-
qDebug() << "No local server port is set.";
391304
}
392305

393306
if (firstPort > 0) {
@@ -406,8 +319,6 @@ int main(int argc, char **argv)
406319
if (portScanner->portScannerError.length() > 0) {
407320
mainWindow.qDisplayError(
408321
portScanner->portScannerError);
409-
qDebug() << "Port error:"
410-
<< portScanner->portScannerError;
411322
}
412323
}
413324

@@ -433,8 +344,6 @@ int main(int argc, char **argv)
433344
mainWindow.qDisplayError(
434345
localServerSettingsFilePath + "<br>" +
435346
"is empty or malformed.");
436-
qDebug() << localServerSettingsFilePath
437-
<< " is empty or malformed.";
438347
}
439348

440349
// Local server has to be started as
@@ -461,7 +370,6 @@ int main(int argc, char **argv)
461370
if (startFileFound == false) {
462371
mainWindow.qDisplayError(
463372
QString("No start page or local server is found."));
464-
qDebug() << "No start page or local server is found.";
465373
}
466374

467375
return application.exec();

src/script-handler.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717

1818
#include <QJsonObject>
19-
#include <QDebug>
20-
#include <QDir>
2119

2220
#include "script-handler.h"
2321

@@ -27,10 +25,6 @@
2725
QScriptHandler::QScriptHandler(QJsonObject scriptJsonObject)
2826
: QObject(0)
2927
{
30-
if (scriptJsonObject.length() == 1) {
31-
qDebug() << "No script settings!";
32-
return;
33-
}
3428

3529
scriptId = scriptJsonObject["id"].toString();
3630

@@ -40,12 +34,6 @@ QScriptHandler::QScriptHandler(QJsonObject scriptJsonObject)
4034
scriptJsonObject["scriptRelativePath"].toString();
4135
}
4236

43-
QFile file(scriptFullFilePath);
44-
if (!file.exists()) {
45-
qDebug() << "File not found:" << scriptFullFilePath;
46-
return;
47-
}
48-
4937
QString scriptInput;
5038
if (scriptJsonObject["scriptInput"].toString().length() > 0) {
5139
scriptInput = scriptJsonObject["scriptInput"].toString();

src/script-handler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class QScriptHandler : public QObject
3232
void displayScriptOutputSignal(QString scriptId,
3333
QString output);
3434
void scriptFinishedSignal(QString scriptId,
35-
QString scriptFullFilePath,
3635
QString scriptAccumulatedErrors);
3736

3837
public slots:
@@ -48,13 +47,11 @@ public slots:
4847
{
4948
QString scriptErrors = scriptProcess.readAllStandardError();
5049
scriptAccumulatedErrors.append(scriptErrors);
51-
scriptAccumulatedErrors.append("\n");
5250
}
5351

5452
void qScriptFinishedSlot()
5553
{
5654
emit scriptFinishedSignal(scriptId,
57-
scriptFullFilePath,
5855
scriptAccumulatedErrors);
5956

6057
scriptProcess.close();

src/webengine-main-window.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public slots:
7070
localServerTester->stop();
7171

7272
qDisplayError(QString("Local server timed out."));
73-
qDebug() << "Local server timed out.";
7473
}
7574
}
7675

@@ -105,8 +104,6 @@ public slots:
105104

106105
void qExitApplicationSlot()
107106
{
108-
qDebug() << "Application exited normally.";
109-
110107
QApplication::exit();
111108
}
112109

0 commit comments

Comments
 (0)