Logging

Overview

Use of log is a great tool to ensure that your scrapes are working correctly as well as troubleshooting problems that arise. Though logging large amounts of information may slow down a scrape, the best way around this is not to remove log writing requests but rather change the verbosity of the logging when running the scrape in a production environment. If you do this, know that you make it harder to troubleshoot some problems should they arise.

The number of methods provided is merely to enhance your ability to log information according to importance.

See Also

  • debug() [log] - Sends a message to the log as an debug message
  • info() [log] - Sends a message to the log as an info message
  • warn() [log] - Sends a message to the log as an warning message
  • error() [log] - Sends a message to the log as a error message

getLogFileName

String session.getLogFileName ( ) (professional and enterprise editions only)

Description

Get the name of the current log file.

Parameters

This method does not receive any parameters.

Return Values

Returns the name of the log file, as a string.

Change Log

Version Description
4.5 Available for professional and enterprise editions.

This method can be very helpful when screen-scraper is running in server mode and you are tracking the log where the scrape of a record is located, or for tracking the location of errors in larger scrapes.

Examples

Get Log's File Name

 // Output the name of the log file to the session log.
 logName =  session.getLogFileName();

log

void session.log ( Object message )

Description

Write message to the log.

Parameters

  • message Message to be written to the log after being converted to a String using String.valueOf( message ).

Return Values

Returns void.

Change Log

Version Description
5.5 Now accepts any Object as a message
4.5 Available for all editions.

When the workbench is running, this will be found under the log tab for the scraping session. When screen-scraper is running in server mode, the message will get sent to the corresponding .log file found in screen-scraper's log folder. When screen-scraper is invoked from the command line, the message will get sent to standard out.

Examples

Write to Log

 // Sends the message to the log.
 session.log( "Inserting extracted data into the database." );

See Also

  • logDebug() [session] - Sends a message to the log as a debugging message
  • logInfo() [session] - Sends a message to the log as an informative message
  • logWarn() [session] - Sends a message to the log as a warning
  • logError() [session] - Sends a message to the log as an error message
  • log() [log] - Write message to the log

logCurrentDateAndTime

void session.logCurrentDateAndTime ( ) (professional and enterprise editions only)

Description

Write current date and time to log (at most verbose level). It is formatted to be human readable.

Parameters

This method does not receive any parameters.

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
4.5 Available for professional and enterprise editions.

Examples

Log Date and Time

 // Output the current date and time to the log.
 session.logCurrentDateAndTime();

logCurrentTime

void session.logCurrentTime ( ) (professional and enterprise editions only)

Description

Write current time to log (at most verbose level). The time is formatted to be human readable.

Parameters

This method does not receive any parameters.

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
4.5 Available for professional and enterprise editions.

Examples

Log Formatted Time

 // Output the current date and time to the log.
 session.logCurrentTime();

logDebug

void session.logDebug ( Object message ) (professional and enterprise editions only)

Description

Write message to the log, at the the debug level (most verbose).

Parameters

  • message Message to be written to the log after being converted to a String using String.valueOf( message ).

Return Values

Returns void.

Change Log

Version Description
5.5 Now accepts any Object as a message
4.5 Available for professional and enterprise editions.

Examples

Write to Log at Debug level

 // Sends the message to the lowest level of logging.
 session.logDebug( "Index: " + session.getVariable( "INDEX" ) );

  • log() [session] - Sends a message to the log as a debugging message
  • logInfo() [session] - Sends a message to the log as an informative message
  • logWarn() [session] - Sends a message to the log as a warning
  • logError() [session] - Sends a message to the log as an error message
  • debug() [log] - Sends a message to the log as a debug message

logElapsedRunningTime

void session.logElapsedRunningTime ( ) (professional and enterprise editions only)

Description

Write scrape run time to the log (at most verbose level). It is formatted to be human readable, including breaking it into days, hours, minutes, and seconds.

Parameters

This method does not receive any parameters.

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
4.5 Available for professional and enterprise editions.

Examples

Log Time the Scrape has been Running

 // Output the running time to the log.
 session.logElapsedRunningTime();

See Also

logError

void session.logError ( Object message ) (professional and enterprise editions only)

Description

Write message to the log, at the the error level (least verbose).

Parameters

  • message Message to be written to the log after being converted to a String using String.valueOf( message ).

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
5.5 Now accepts any Object as a message
4.5 Available for professional and enterprise editions.

Examples

Write to Log at Error level

 // Sends the message to the highest level of logging.
 session.logError( "Error parsing date: " + session.getVariable( "DATE" ) );

  • log() [session] - Sends a message to the log as a debugging message
  • logDebug() [session] - Sends a message to the log as a debugging message
  • logInfo() [session] - Sends a message to the log as an informative message
  • logWarn() [session] - Sends a message to the log as a warning
  • error() [log] - Sends a message to the log as an error message

logInfo

void session.logInfo ( Object message ) (professional and enterprise editions only)

Description

Write message to the log, at the the info level (second most verbose).

Parameters

  • message Message to be written to the log after being converted to a String using String.valueOf( message ).

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
5.5 Now accepts any Object as a message
4.5 Available for professional and enterprise editions.

Examples

Write to Log at Info level

 // Sends the message to the second lowest level of logging.
 session.logInfo( "Traversing search results pages..." );

  • log() [session] - Sends a message to the log as a debugging message
  • logDebug() [session] - Sends a message to the log as a debugging message
  • logWarn() [session] - Sends a message to the log as a warning
  • logError() [session] - Sends a message to the log as an error message
  • info() [log] - Sends a message to the log as an info message

logVariables

void session.logVariables ( ) (professional and enterprise editions only)

Description

Write all session variables to log.

Parameters

This method does not receive any parameters.

Return Values

Returns void.

Change Log

Version Description
5.0 Added for all editions.

Examples

Log All Session Variables

 // Write Variables to Log
 session.logVariables();

See Also

  • berakpoint [dataSet] - Pause scrape and display breakpoint window.

logWarn

void session.logWarn ( Object message ) (professional and enterprise editions only)

Description

Write message to the log, at the the warn level (third most verbose).

Parameters

  • message Message to be written to the log after being converted to a String using String.valueOf( message ).

Return Values

Returns void. If an error occurs, an error will be thrown.

Change Log

Version Description
5.5 Now accepts any Object as a message
4.5 Available for professional and enterprise editions.

Examples

Write to Log at Info level

 // Sends the message to the third level of logging.
 session.logWarn( "Warning! Received a 404 response."  );

  • log() [session] - Sends a message to the log as a debugging message
  • logDebug() [session] - Sends a message to the log as a debugging message
  • logInfo() [session] - Sends a message to the log as an informative message
  • logError() [session] - Sends a message to the log as an error message
  • warn() [log] - Sends a message to the log as an warning message