[Cosm Logo]

Log File Functions


CosmLogOpen

Syntax

#include "cosm/log.h"
s32 CosmLogOpen( cosm_LOG * log, ascii * filename, u32 max_level,
  u32 mode );

Description

Initialize the log, setting the filename, max_level, and mode. If COSM_LOG_MODE_NUMBER then log any message with an equal or lower level than max_level. If COSM_LOG_MODE_BITS then log any message with it's level matching a bit in max_level. Initializing a log with a NULL filename or invalid mode causes failure.

Log modes:

COSM_LOG_MODE_NUMBER
Log any message with an equal or lower level than max_level.
COSM_LOG_MODE_BITS
Log any message with it's level matching a bit in max_level.

Return Values

COSM_PASS on success, or an error code on failure.

Errors

COSM_LOG_ERROR_MODE
The specified mode is invalid.
COSM_LOG_ERROR_NAME
The specified filename is invalid.
COSM_LOG_ERROR_INIT
log is invalid.
COSM_LOG_ERROR_ACCESS
Unable to get write access to the log file.

Example

  cosm_LOG log;
  s32 result;

  CosmMemSet( &log, sizeof( cosm_LOG ), 0 );

  result = CosmLogOpen( &log, "/var/log/cosmlog", 5,
    COSM_LOG_MODE_NUMBER );

  if ( result == COSM_PASS )
  {
    CosmPrint( "Log file /var/log/cosmlog initialized.\n" );
  }
  else
  {
    CosmPrint( "Unable to open /var/log/cosmlog.\n" );
  }

CosmLog

Syntax

#include "cosm/log.h"
s32 CosmLog( cosm_LOG * log, u32 level, u32 echo,
  const utf8 * format, ... );

Description

Write the formatted string to the log. See CosmPrint for format info. The string will be logged only if the level is acceptable to the open log. Level 0 will always be logged. If echo is COSM_LOG_ECHO and the level passes then the string will also be printed to the standard output device. Otherwise if level does not pass or echo is COSM_LOG_NOECHO nothing will be printed.

Return Values

COSM_PASS on success, or an error code on failure.

Errors

COSM_LOG_ERROR_INIT
The log file wasn't initialized using CosmLogOpen.
COSM_LOG_ERROR_ACCESS
Unable to get write access to the log file.

Example

  cosm_LOG log;

  CosmMemSet( &log, sizeof( cosm_LOG ), 0 );

  CosmLogOpen( &log, "file.log", 5, COSM_LOG_MODE_NUMBER );
  /* check for errors */

  CosmLog( &log, 3, COSM_LOG_NOECHO,
    "This is logged. 3 is less than 5.\n" );
  CosmLog( &log, 8, COSM_LOG_NOECHO,
    "This is not logged. 8 is greater than 5.\n" );

  CosmLogClose( &log );

  CosmLogOpen( &log, "file.log", 0x55, COSM_LOG_MODE_BITS );
  /* check for errors */

  CosmLog( &log, 0x03, COSM_LOG_NOECHO,
    "This is logged. ( 0x03 & 0x55 ) != 0.\n" );
  CosmLog( &log, 0x08, COSM_LOG_NOECHO,
    "This is not logged. ( 0x08 & 0x55 ) == 0.\n" );
  CosmLog( &log, 0x00, COSM_LOG_NOECHO,
    "This is logged. Level 0 is ALWAYS logged.\n" );

  CosmLogClose( &log );

CosmLogClose

Syntax

#include "cosm/log.h"
s32 CosmLogClose( cosm_LOG * log );

Description

Close the log.

Return Values

COSM_PASS on success.

Errors

None.

Example

  cosm_LOG log;

  CosmMemSet( &log, sizeof( cosm_LOG ), 0 );

  /* ... */

  CosmLogClose( &log );

© Copyright Mithral Communications & Design Inc. 1995-2017. All rights reserved. Mithral® and Cosm® are trademarks of Mithral Communications & Design Inc.
Document last modified: Jun 01, 2012