MySQL Shell 9.0  /  MySQL Shell Logging and Debug  /  Application Log

12.1 Application Log

The location of the MySQL Shell application log file is the user configuration path and the file is named mysqlsh.log. By default, MySQL Shell sends logging information at logging level 5 (error, warning, and informational messages) to this file.

Note

Log messages are timestamped in UTC format.

To change the level of logging information that is sent, or to disable logging to the application log file, choose one of these options:

The available logging levels are as listed in Table 12.1, “Logging levels in MySQL Shell”. If you specify a logging level of 1 or none for the option, logging to the application log file is disabled. All other values leave logging enabled and set the level of detail in the log file. The option requires a value.

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:

$> mysqlsh --log-level=4
$> 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:

$> mysqlsh --log-level=@8
$> 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. This is the value of the resultFormat MySQL Shell configuration option, unless JSON wrapping has been activated by starting MySQL Shell with the --json command line 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 application log file is %APPDATA%\MySQL\mysqlsh\mysqlsh.log. To find the location of %APPDATA% on your system, echo it from the command line. For example:

C:>echo %APPDATA%

C:\Users\exampleuser\AppData\Roaming

On Windows, the path is the %APPDATA% folder specific to the user, with MySQL\mysqlsh added. Using the above example the path would be C:\Users\exampleuser\AppData\Roaming\MySQL\mysqlsh\mysqlsh.log .

If you want the application log file to be stored in a different location, you can override the default user configuration path by defining the environment variable MYSQLSH_USER_CONFIG_HOME. The value of this variable replaces %AppData%\MySQL\mysqlsh\ on Windows.

You can also use the --log-file option to override the user configuration path when you run mysqlsh from the command line. The --log-file option applies to the individual MySQL Shell instance, meaning that different instances can write to different locations.

Log File Location on Unix-based Systems

For a machine running Unix, the default path to the application log file 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 log.

If you want the application log file to be stored in a different location, you can override the default user configuration path by defining the environment variable MYSQLSH_USER_CONFIG_HOME. The value of this variable replaces ~/.mysqlsh/ on Unix.

You can also use the --log-file option to override the user configuration path when you run mysqlsh from the command line. The --log-file option applies to the individual MySQL Shell instance, meaning that different instances can write to different locations.