Logger 3.0.0: Explicit Conversions Using logger.tochar

This article is part of a series about the upcoming release of Logger 3.0.0. A full list of these posts can be found here.

Logger uses simple conversion functions to convert standard Oracle data types to strings. In this release we exposed this functionality called: logger.tochar.

The purpose of exposing this overloaded function is to allow developers to leverage its functionality both when calling Logger and for your own purposes.

A common example its use is when you want to log a non-string variable such as a date:

-- NLS setting will vary on each system
-- This shows a less detailed date format.
alter session set nls_date_format='YYYY/MM/DD';

begin
  logger.log('Implicit conversion: ' || sysdate);
  logger.log('logger.tochar conversion: ' || logger.tochar(sysdate));
end;
/

select text
from logger_logs_5_min;

TEXT
-----------------------------------------------
Implicit conversion: 2015/03/06
logger.tochar conversion: 06-MAR-2015 11:15:13

You'll notice that the implicit conversion may not always display everything you want it to, while calling logger.tochar will display all the details. This can save you a lot of time doing manual explicit conversions.

Here is a list of data types that logger.tochar supports and the format it will use:

Data Type Format
Number
Date DD-MON-YYYY HH24:MI:SS
Timestamp DD-MON-YYYY HH24:MI:SS:FF
Timestamp with time zone DD-MON-YYYY HH24:MI:SS:FF TZR
Timestamp with local time zone DD-MON-YYYY HH24:MI:SS:FF TZR
Boolean TRUE/FALSE

Unlike most of the methods in Logger, logger.tochar is not affected by the current logging level nor if Logger is being run in no_op mode. This is because we think that developers will use it for other purposes besides logging.