Project

General

Profile

Scol standard library package  0.3.1
Common and usefull functions for all Scol applications
The error API.

Functions

 std_errAddType (err, num, str)
 Add a new predefined error in a manager.
 std_errClearTypes (err)
 Reset all predefined error in a manager.
 std_errClose (err)
 Close a manager. If TMPFILE is enabled, the temporary file is closed and its content is lost.
 std_errCopy (err, filename)
 Open a new manager in copying the configuration of another one.
 std_errGetConsole (err)
 Returns if the Scol console is shown (for this manager) Only if this API manages the Scol console, if another code show or hide it, this return can be wrong.
 std_errGetContent (err)
 Returns the content of the log file (for a manager) This can be a hard file or a temporary file.
 std_errGetEnabled (err)
 Returns the current state of a manager.
 std_errGetFilename (err)
 Returns the path of the log file of a manager.
 std_errGetFoo (err)
 Returns if, for a manager, the message are displayed in the Scol console.
 std_errGetIsTemp (err)
 Returns if a temporary file is used (for a manager)
 std_errGetLast (err)
 Returns the last written message.
 std_errGetMask (err)
 Returns the current mask of a manager.
 std_errGetObjDisabled ()
 Returns a list of all manager disabled.
 std_errGetObjEnabled ()
 Returns a list of all manager enabled.
 std_errGetPeriod (err)
 Get the period. Period is unused, so this function is unused too !
 std_errGetTypeFromNumber (err, number)
 Returns the string error message for a given number code error (for a manager)
 std_errGetTypeFromString (err, str)
 Returns the number code error from a given string error message (for a manager)
 std_errGetTypes (err)
 Returns the list of defined eror types for a manager.
 std_errNumber (err, num, mask)
 Send a predefined error to a manager. According the manager settings, the string can be written in the Scol console, in the application log file if the client set it, in the customized log file, ...
 std_errNumberAndInConsole (err, csl, num, mask)
 Same thing than std_errNumber. In addition, you can print the message error in a EasyConsole (see in lib/console directory)
 std_errObjLast ()
 Returns the last created(opened) manager.
 std_errObjNumbers ()
 Return the number of opened managers.
 std_errOpen (mask)
 Open a new manager By default, the manager is ENABLED, the console message and the console are disabled. Other parameters are at nil.
 std_errOpenLog (err, filename)
 Open a new log file The current date is written.
 std_errOpenLogNow (err, name)
 Open a new log file. The filename is the current date and time with a prefix : my_folder/the_prefix_2013_12_14-17_25_21.log The current date is written. The TMPFILE must be disabled.
 std_errRemoveType (err, num)
 Remove a predefined error in a manager.
 std_errSaveTemp (err, filename)
 A conivience function. Save the content of the temporary file in a hard file.
 std_errSetConsole (err, state)
 Set the state of the Scol console if another code show or hide it, the effect can be different.
 std_errSetEnabled (err, state)
 Set the current state of a manager.
 std_errSetFoo (err, state)
 Set if error message are displayed in the Scol console.
 std_errSetIsTemp (err, isTmp, filename)
 Set if a manager uses (or not) a temporary file. If the old and the new value are the same, no change is done. If the new value is 1 and the old value was 0, a new temporary file is created and the content of the old 'hard' file is copied in the new temporary file. The old 'hard' file is unchanged and no new message will be written. If the new file is 0 and the 'hard' file name is not nil, the file is created and the content of the old temporary file is copied. This last one is closed (and destroyed). All other configuration or an invalid argument will return a nil value.
 std_errSetMask (err, mask)
 Set the current mask of a manager.
 std_errString (err, str, mask)
 Send a new string message error to a manager. According the manager settings, the string can be written in the Scol console, in the application log file if the client set it, in the customized log file, ...
 std_errStringAndInConsole (err, csl, str, mask)
 Same thing than std_errString. In addition, you can print the string message error in a EasyConsole (see in lib/console directory)
 std_errUndoMask (err)
 Perform an 'undo' to the mask of a manager.

Detailed Description

Package to load : lib/std/error.pkg

This API provides an high level method to easily include a customized error manager

You can :

  • define your masks yourself
  • enabled / disabled this manager
  • define your code numbers and messages error
  • write - or not - in the Scol console
  • use a hard file log or a temporary file log
  • and more things yet

It is NOT recommanded to use the internal STD_ERROR structure to any application. Use this API instead.

To use it with the Console library (lib/console), this API requires too the lib/console/console.pkg package.

Function Documentation

std_errOpen ( mask  )

Open a new manager By default, the manager is ENABLED, the console message and the console are disabled. Other parameters are at nil.

Prototype: fun [I] STD_ERROR

Parameters
I: a mask
Returns
STD_ERROR : the new manager object
std_errOpenLog ( err  ,
filename   
)

Open a new log file The current date is written.

Prototype: fun [STD_ERROR S] STD_ERROR

Parameters
STD_ERROR: a manager object
S: a filename for the log file if the TMPFILE is disabled if TMPFILE is enabled, this argument is ignored and could be nil.
Remarks
if any, the current file is overwritten.
Returns
STD_ERROR : the same manager object or nil if error
std_errOpenLogNow ( err  ,
name   
)

Open a new log file. The filename is the current date and time with a prefix : my_folder/the_prefix_2013_12_14-17_25_21.log The current date is written. The TMPFILE must be disabled.

Prototype: fun [STD_ERROR S] STD_ERROR

Parameters
STD_ERROR: a manager object
S: a filename for the log file such as "my_folder/the_prefix"

Note : if any, the current file is overwritten.

Returns
STD_ERROR : the same manager object or nil if error (manager is nil or TMPFILE enabled)
std_errClose ( err  )

Close a manager. If TMPFILE is enabled, the temporary file is closed and its content is lost.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
S: a filename for the log file
Returns
I : 0 if success, 1 if the manager is already closed (or not created), 2 if the temporary file can not be closed correctly
Examples:
3d_test/test_3d.pkg_.
std_errCopy ( err  ,
filename   
)

Open a new manager in copying the configuration of another one.

Prototype: fun [STD_ERROR S] STD_ERROR

Parameters
STD_ERROR: a manager object
S: a filename for the log file or nil if a temporary file is prefered

Note : if any, the current file is overwritten.

Returns
STD_ERROR : the new manager object or nil if error
std_errGetMask ( err  )

Returns the current mask of a manager.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : the current mask or nil if error
std_errSetMask ( err  ,
mask   
)

Set the current mask of a manager.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: the new mask to set
Returns
STD_ERROR : the current manager or nil if error
std_errUndoMask ( err  )

Perform an 'undo' to the mask of a manager.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
STD_ERROR : the same manager or nil if error
std_errGetPeriod ( err  )

Get the period. Period is unused, so this function is unused too !

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : the manager period or nil if error
std_errGetFilename ( err  )

Returns the path of the log file of a manager.

Prototype: fun [STD_ERROR] S

Parameters
STD_ERROR: a manager object
Returns
S : the path or nil if error (by example, a temporary file is used)
std_errGetEnabled ( err  )

Returns the current state of a manager.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : 1 if this manager is enabled, 0 if disabled or nil if error
std_errSetEnabled ( err  ,
state   
)

Set the current state of a manager.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: the new state : 1 -> enabled, 0 to disable. Another value is ignored.
Returns
STD_ERROR : the same manager or nil if error (manager is nil or bad value)
std_errGetFoo ( err  )

Returns if, for a manager, the message are displayed in the Scol console.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : 1, yes, 0, no or nil if error
std_errSetFoo ( err  ,
state   
)

Set if error message are displayed in the Scol console.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: the new state : 1 -> enabled, 0 to disable. Another value is ignored.
Returns
STD_ERROR : the same manager or nil if error (manager is nil or bad value)
std_errGetLast ( err  )

Returns the last written message.

Prototype: fun [STD_ERROR] [I S]

Parameters
STD_ERROR: a manager object
Returns
[I S] : a tuple with the last code number and the last string or nil if error
std_errGetContent ( err  )

Returns the content of the log file (for a manager) This can be a hard file or a temporary file.

Prototype: fun [STD_ERROR] S

Parameters
STD_ERROR: a manager object
Returns
S : the content or nil if error
std_errSaveTemp ( err  ,
filename   
)

A conivience function. Save the content of the temporary file in a hard file.

Prototype: fun [STD_ERROR W] I

Parameters
STD_ERROR: a manager object
W: a write reference path name to save the current datas
Returns
I : 0 if success or nil or another value not null if error
std_errGetTypes ( err  )

Returns the list of defined eror types for a manager.

Prototype: fun [STD_ERROR] [[I S] r1]

Parameters
STD_ERROR: a manager object
Returns
[[I S] r1] : the list or nil if error
std_errGetTypeFromNumber ( err  ,
number   
)

Returns the string error message for a given number code error (for a manager)

Prototype: fun [STD_ERROR I] S

Parameters
STD_ERROR: a manager object
I: an error code number
Returns
S : this error message or nil if error
std_errGetTypeFromString ( err  ,
str   
)

Returns the number code error from a given string error message (for a manager)

Prototype: fun [STD_ERROR S] I

Parameters
STD_ERRO]: a manager object
S: a string error (case-insensitive)
Returns
I : the error number or nil if error
std_errAddType ( err  ,
num  ,
str   
)

Add a new predefined error in a manager.

Prototype: fun [STD_ERROR I S] STD_ERROR

Parameters
STD_ERROR: a manager object
I: a new number error
S: the appropriate message string
Returns
STD_ERROR : the same manager or nil if error (manager is nil or number already existing)
std_errClearTypes ( err  )

Reset all predefined error in a manager.

Prototype: fun [STD_ERROR] STD_ERROR

Parameters
STD_ERROR: a manager object
Returns
STD_ERROR : the same manager
std_errRemoveType ( err  ,
num   
)

Remove a predefined error in a manager.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: a number error to remove
Returns
STD_ERROR : the same manager or nil if error
std_errGetIsTemp ( err  )

Returns if a temporary file is used (for a manager)

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : yes (1) or no (0) or nil if error
std_errSetIsTemp ( err  ,
isTmp  ,
filename   
)

Set if a manager uses (or not) a temporary file. If the old and the new value are the same, no change is done. If the new value is 1 and the old value was 0, a new temporary file is created and the content of the old 'hard' file is copied in the new temporary file. The old 'hard' file is unchanged and no new message will be written. If the new file is 0 and the 'hard' file name is not nil, the file is created and the content of the old temporary file is copied. This last one is closed (and destroyed). All other configuration or an invalid argument will return a nil value.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: 1 to use a temporary file, else 0
S: a filename (should be nil if the temporay file will be used)
Returns
STD_ERROR : the same manager or nil if error
std_errGetConsole ( err  )

Returns if the Scol console is shown (for this manager) Only if this API manages the Scol console, if another code show or hide it, this return can be wrong.

Prototype: fun [STD_ERROR] I

Parameters
STD_ERROR: a manager object
Returns
I : show (1) or hide (0) or nil if error
std_errSetConsole ( err  ,
state   
)

Set the state of the Scol console if another code show or hide it, the effect can be different.

Prototype: fun [STD_ERROR I] STD_ERROR

Parameters
STD_ERROR: a manager object
I: 1 to show the Scol console, 0 to hide it.
Returns
STD_ERROR : the same manager
std_errString ( err  ,
str  ,
mask   
)

Send a new string message error to a manager. According the manager settings, the string can be written in the Scol console, in the application log file if the client set it, in the customized log file, ...

Prototype: fun [STD_ERROR S I] I

Parameters
STD_ERROR: a manager object
S: the string message error
I: a mask for this message. It is tested with the mask of the manager to determine wether the message should be written. If the test is positive, the message is immediatly written. Thus, the logical 'mask_of_manager & mask_of_this_message' must be not null to write the message.
Returns
I : 0 if success, 1 if the manager is nil, 2 if the manager is disabled, 3 if the test is negative, 4 if the message can not be written in the temporary file, 5 if the message cannot be written in the 'hard' file.
Examples:
3d_test/test_3d.pkg_.
std_errNumber ( err  ,
num  ,
mask   
)

Send a predefined error to a manager. According the manager settings, the string can be written in the Scol console, in the application log file if the client set it, in the customized log file, ...

Prototype: fun [STD_ERROR I I] I

Parameters
STD_ERROR: a manager object
I: a predefined number error
I: a mask for this message. It is tested with the mask of the manager to determine wether the message should be written. If the test is positive, the message is immediatly written. Thus, the logical 'mask_of_manager & mask_of_this_message' must be at not null to write the message.
Returns
I : 0 if success, 1 if the manager is nil, 2 if the manager is disabled, 3 if the test is negative, 4 if the message can not be written in the temporary file, 5 if the message cannot be written in the 'hard' file or 6 if the number is not a predefined error.
std_errObjNumbers ( )

Return the number of opened managers.

Prototype: fun [ ] I

Returns
I : the number
std_errObjLast ( )

Returns the last created(opened) manager.

Prototype: fun [] STD_ERROR

Returns
STD_ERROR : this last (can be nil if no manager open)
std_errGetObjEnabled ( )

Returns a list of all manager enabled.

Prototype: fun [] [STD_ERROR r1]

Returns
[STD_ERROR r1] : this list (can be nil if no manager enabled)
std_errGetObjDisabled ( )

Returns a list of all manager disabled.

Prototype: fun [] [STD_ERROR r1]

Returns
[STD_ERROR r1] : this list (can be nil if no manager disabled)
std_errStringAndInConsole ( err  ,
csl  ,
str  ,
mask   
)

Same thing than std_errString. In addition, you can print the string message error in a EasyConsole (see in lib/console directory)

Prototype: fun [STD_ERROR CONSOLE S I] I

Parameters
STD_ERROR: a manager object
CONSOLE: an EasyConsole already created.
S: the string message error
I: a mask for this message. It is tested with the mask of the manager to determine wether the message should be written. If the test is positive, the message is immediatly written. Thus, the logical 'mask_of_manager & mask_of_this_message' must be at not null to write the message.
Remarks
: The mask is always ignored to writing in the EsayConsole.
Returns
I : 0 if success, 1 if the manager is nil, 2 if the manager is disabled, 3 if the test is negative, 4 if the message can not be written in the temporary file, 5 if the message cannot be written in the 'hard' file.
std_errNumberAndInConsole ( err  ,
csl  ,
num  ,
mask   
)

Same thing than std_errNumber. In addition, you can print the message error in a EasyConsole (see in lib/console directory)

Prototype: fun [STD_ERROR CONSOLE I I] I

Parameters
STD_ERROR: a manager object
CONSOLE: an EasyConsole object
I: a predefined number error
I: a mask for this message. It is tested with the mask of the manager to determine wether the message should be written. If the test is positive, the message is immediatly written. Thus, the logical 'mask_of_manager & mask_of_this_message' must be at not null to write the message.
Remarks
: The mask is always ignored to writing in the EsayConsole.
Returns
I : 0 if success, 1 if the manager is nil, 2 if the manager is disabled, 3 if the test is negative, 4 if the message can not be written in the temporary file, 5 if the message cannot be written in the 'hard' file or 6 if the number is not a predefined error.