log.bi

Summary
log.bi
About this ModuleThe logging module is meant to be a very simple log that is also very capable.
Code LicenseCopyright © 2007-2014, FreeBASIC Extended Library Development Group
ext
Enumerations
LOGLEVELThe different severities recognized by the logger.
LOG_METHODSThe different actions the logger can take.
Types
log_custom_subThe sub signature used by the LOG_CUSTOM logger.
custom_data_freeThe sub signature used as the memory releaser for any passed data.
Functions
setNumberOfLogChannelsBy default there is only one logging channel, however you can reserve more channels so that you may log different things to different places easily.
setLogMethodSet the log channel’s method to use, must be one of LOG_METHODS.
setLogLevelSet the level that actions are taken at, any log messages lower than that level are ignored.
Macros
DEBUGSend a DEBUG message to the default channel.
DEBUGtoSend a DEBUG message to the specified channel.
INFOSend a INFO message to the default channel.
INFOtoSend a INFO message to the specified channel.
WARNSend a WARN message to the default channel.
WARNtoSend a WARN message to the specified channel.
FATALSend a FATAL message to the default channel.
FATALtoSend a FATAL message to the specified channel.

About this Module

The logging module is meant to be a very simple log that is also very capable.  For basic usage absolutely no configuration is needed, just start using the DEBUG, INFO, WARN or FATAL logging macros.

For an example showing how to use this module see https://code.google.com/p/fb-extended-lib/source/browse/examples/logging/log.bas or check your examples/logging directory.

When using this module in a multithreaded environment all logging happens asynchronously in the background.

Code License

Copyright © 2007-2014, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com/p/fb-extended-lib/wiki/License

ext

Summary
Enumerations
LOGLEVELThe different severities recognized by the logger.
LOG_METHODSThe different actions the logger can take.
Types
log_custom_subThe sub signature used by the LOG_CUSTOM logger.
custom_data_freeThe sub signature used as the memory releaser for any passed data.
Functions
setNumberOfLogChannelsBy default there is only one logging channel, however you can reserve more channels so that you may log different things to different places easily.
setLogMethodSet the log channel’s method to use, must be one of LOG_METHODS.
setLogLevelSet the level that actions are taken at, any log messages lower than that level are ignored.
Macros
DEBUGSend a DEBUG message to the default channel.
DEBUGtoSend a DEBUG message to the specified channel.
INFOSend a INFO message to the default channel.
INFOtoSend a INFO message to the specified channel.
WARNSend a WARN message to the default channel.
WARNtoSend a WARN message to the specified channel.
FATALSend a FATAL message to the default channel.
FATALtoSend a FATAL message to the specified channel.

Enumerations

LOGLEVEL

The different severities recognized by the logger.

Values

_DEBUGThis level is typically only important to developers debugging the program
_INFOThis level does not represent an error just important information.
_WARNThis level represents an error that the program was able to handle.
_FATALThis level represents an unrecoverable error.

LOG_METHODS

The different actions the logger can take.

Values

LOG_NULLDo absolutely nothing.
LOG_PRINTPrint the log message to the console.
LOG_FILEWrite the log messages to a file, set with setLogMethod
LOG_CUSTOMWrite your own logger function

Types

log_custom_sub

type log_custom_sub as sub(byval as LOGLEVEL,
byref _msg_ as const string,
byref _filen_ as const string,
byval _linen_ as integer,
byval _data_ as any ptr)

The sub signature used by the LOG_CUSTOM logger.

Parameters

lthe LOGLEVEL of the message
_msg_the actual message
_filen_the name of the file that the message is from
_linen_the line number in filen the message is from
_data_arbitrary data

custom_data_free

type custom_data_free as sub (byval as any ptr)

The sub signature used as the memory releaser for any passed data.

Functions

setNumberOfLogChannels

declare function setNumberOfLogChannels(byval c as uinteger) as bool

By default there is only one logging channel, however you can reserve more channels so that you may log different things to different places easily.  Channels are numbered starting at 0 and you can request as many as 256 channels (which would be numbered 0 to 255)

Parameters

cthe number of channels to reserve.

Returns

TRUE on error, invalid arg or memory allocation failure, existing channel(s) not changed on error

setLogMethod

declare sub setLogMethod overload (byval as LOG_METHODS,  
byval as any ptr =  0,
byval as any ptr =  0,
byval as any ptr =  0)

Set the log channel’s method to use, must be one of LOG_METHODS.  The default setting is LOG_PRINT.

Parameters

cOptional The log channel to change, can be completely omitted (comma and all) for default channel
lmthe LOG_METHODS to use
sfor LOG_FILE this is the filename (is optional, default is command(0).log, recommended to set to a writable file.), for LOG_CUSTOM this is the method to call Not Used for other LOG_METHODS
fdpointer for arbitrary data to be passed to the LOG_CUSTOM method.
fffunction to be used to free custom data when logger is finalized.

setLogLevel

declare sub setLogLevel overload (byval as LOGLEVEL)

Set the level that actions are taken at, any log messages lower than that level are ignored.  The default level is _INFO.

Parameters

cOptional The logger channel to change, can be completely omitted (comma and all) for default channel
lLOGLEVEL that you wish to set as minimum.

Macros

DEBUG

#define DEBUG(m) _LOG(_DEBUG,m,0)

Send a DEBUG message to the default channel.

Parameters

mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

DEBUGto

#define DEBUGto(c,
m) _LOG(_DEBUG,m,(c))

Send a DEBUG message to the specified channel.

Parameters

cthe channel number to send to
mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

INFO

#define INFO(m) _LOG(_INFO,m,0)

Send a INFO message to the default channel.

Parameters

mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

INFOto

#define INFOto(c,
m) _LOG(_INFO,m,(c))

Send a INFO message to the specified channel.

Parameters

cthe channel number to send to
mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

WARN

#define WARN(m) _LOG(_WARN,m,0)

Send a WARN message to the default channel.

Parameters

mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

WARNto

#define WARNto(c,
m) _LOG(_WARN,m,(c))

Send a WARN message to the specified channel.

Parameters

cthe channel number to send to
mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

FATAL

#define FATAL(m) _LOG(_FATAL,m,0)

Send a FATAL message to the default channel.

Parameters

mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

FATALto

#define FATALto(c,
m) _LOG(_FATAL,m,(c))

Send a FATAL message to the specified channel.

Parameters

cthe channel number to send to
mthe message to send.

Note

All messages must be a value that is either already a string or is able to be converted to a string, i.e. it has a cast() as string operator.

type log_custom_sub as sub(byval as LOGLEVEL,
byref _msg_ as const string,
byref _filen_ as const string,
byval _linen_ as integer,
byval _data_ as any ptr)
The sub signature used by the LOG_CUSTOM logger.
type custom_data_free as sub (byval as any ptr)
The sub signature used as the memory releaser for any passed data.
declare function setNumberOfLogChannels(byval c as uinteger) as bool
By default there is only one logging channel, however you can reserve more channels so that you may log different things to different places easily.
declare sub setLogMethod overload (byval as LOG_METHODS,  
byval as any ptr =  0,
byval as any ptr =  0,
byval as any ptr =  0)
Set the log channel’s method to use, must be one of LOG_METHODS.
The different actions the logger can take.
declare sub setLogLevel overload (byval as LOGLEVEL)
Set the level that actions are taken at, any log messages lower than that level are ignored.
#define DEBUG(m) _LOG(_DEBUG,m,0)
Send a DEBUG message to the default channel.
#define DEBUGto(c,
m) _LOG(_DEBUG,m,(c))
Send a DEBUG message to the specified channel.
#define INFO(m) _LOG(_INFO,m,0)
Send a INFO message to the default channel.
#define INFOto(c,
m) _LOG(_INFO,m,(c))
Send a INFO message to the specified channel.
#define WARN(m) _LOG(_WARN,m,0)
Send a WARN message to the default channel.
#define WARNto(c,
m) _LOG(_WARN,m,(c))
Send a WARN message to the specified channel.
#define FATAL(m) _LOG(_FATAL,m,0)
Send a FATAL message to the default channel.
#define FATALto(c,
m) _LOG(_FATAL,m,(c))
Send a FATAL message to the specified channel.
The different severities recognized by the logger.