MySQL Shell 8.0  /  MySQL Shell Application Log  /  Application Log

7.1 Application Log

MySQL Shell can be configured to generate an application log file with information about issues of varying severity. You can use this information to verify the state of MySQL Shell while it is running.

The location of the log file is the user configuration path and the file is named mysqlsh.log.

By default, logging is disabled in MySQL Shell. To enable logging use the --log-level command-line option when starting MySQL Shell, or use either the \option command or the shell.options object to set the logLevel MySQL Shell configuration option. If the option is not set on the command line or in the configuration file, or if you specify a logging level of 1 or none, logging is disabled. All other values enable logging and set the level of detail in the log as follows:

Logging Level - Numeric Logging Level - Text Meaning

1

none

None, the default

2

internal

Internal Error

3

error

Error

4

warning

Warning

5

info

Informational

6

debug

Debug

7

debug2

Debug2

8

debug3

Debug3

With the --log-level command-line option, you can specify the logging level using its text name or the numeric equivalent, so the following examples have the same effect:

shell> mysqlsh --log-level=4
shell> mysqlsh --log-level=warning

With the logLevel MySQL Shell configuration option, you can only specify a numeric logging level.

If you prepend the logging level with @ (at sign), log entries are output to an additional viewable location as well as being written to the MySQL Shell log file. The following examples have the same effect:

shell> mysqlsh --log-level=@8
shell> mysqlsh --log-level=@debug3

On Unix-based systems, the log entries are output to stderr in the output format that is currently set for MySQL Shell (which is the value of the outputFormat configuration option). On Windows systems, the log entries are printed using the OutputDebugString() function, whose output can be viewed in an application debugger, the system debugger, or a capture tool for debug output.

The MySQL Shell log file format is plain text and entries contain a timestamp and description of the problem, along with the logging level from the above list. For example:

2016-04-05 22:23:01: Error: Default Domain: (shell):1:8: MySQLError: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near '' at line 1 (1064) in session.sql("select * from t
limit").execute().all();

Log File Location on Windows

On Windows, the default path to the log file is %APPDATA%\MySQL\mysqlsh\mysqlsh.log

To find the location of %APPDATA% on your system, echo it from the comand-line. For example:

C:>echo %APPDATA%

C:\Users\exampleuser\AppData\Roaming

On Windows, the path is determined by the result of gathering the %APPDATA% folder specific to that user, and then appending MySQL\mysqlsh. Using the above example, we end up with:

C:\Users\exampleuser\AppData\Roaming\MySQL\mysqlsh\mysqlsh.log

Log File Location on Unix-based Systems

For a machine running Unix, the default path is ~/.mysqlsh/mysqlsh.log where ~ represents the user's home directory. The environment variable HOME also represents the user's home directory. Appending .mysqlsh to the user's home directory determines the default path to the logs. For example:

C:>echo $HOME

/home/exampleuser

shell> less /home/exampleuser/.mysqlsh/mysqlsh.log

The default user configuration path can be overridden on all platforms by defining the environment variable MYSQL_USER_CONFIG_HOME. The value of this variable replaces %AppData%\MySQL\mysqlsh\ on Windows or ~/.mysqlsh/ on Unix.