# Logging

Logging, or event logging, is a useful method of gaining meaningful information about the state of the application during deployed mode. For example, it can be used to log information about the project, such as project handling, camera discovery, state information or custom messages generated by a user's JavaScript code.

There are several ways to log messages while in deployed mode:

- Logging to the Output window or a Browser's Console

  The JavaScript console.log() function is used for info-level log messages. The log() function is a built-in JavaScript function that is visible in the Cognex DesignerOutput window and a Web browser's console log. This log will also be routed to the controller's log system, so it is saved onto the controller.

  The controller $ Functions: System function, $System.Log.Write(), is used for implementing different log levels (error and warning). These logs are displayed in the Output window, but will not be shown in a Web browser's console log.

- Logging to a File

  The controller $ Functions: System functions, $System.File.WriteText() or $System.File.AppendText(), can be used to log text information directly to a file on the public file system on the controller. All file paths used are relative to the public file system. Any directory can be used on the public file system, but if it does not exist, it will not be created. The user can create directories via an FTP connection to the controller.

  These functions are also callable from JavaScript and via WebPage Elements Event Handler Scripts.

  Additional System functions are available which allow one to check if a file exists, $System.File.Exists(), or delete an existing file, $System.File.Delete().

  Note:
  - Logging to a file adds the additional overhead of file IO operations (open-write-close) and increases execution time when compared to logging to memory.
  - Files within the public file system are not considered project data, except for the content of the specific project directories under the Projects subdirectory. Care must be taken to avoid inadvertently overwriting the files of another project