Log File FunctionsCosmLogOpenSyntax#include "cosm/log.h" s32 CosmLogOpen( cosm_LOG * log, ascii * filename, u32 max_level, u32 mode ); DescriptionInitialize 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:
Return ValuesCOSM_PASS on success, or an error code on failure. Errors
Examplecosm_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" ); } CosmLogSyntax#include "cosm/log.h" s32 CosmLog( cosm_LOG * log, u32 level, u32 echo, const utf8 * format, ... ); DescriptionWrite 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 ValuesCOSM_PASS on success, or an error code on failure. Errors
Examplecosm_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 ); CosmLogCloseSyntax#include "cosm/log.h" s32 CosmLogClose( cosm_LOG * log ); DescriptionClose the log. Return ValuesCOSM_PASS on success. ErrorsNone. Examplecosm_LOG log; CosmMemSet( &log, sizeof( cosm_LOG ), 0 ); /* ... */ CosmLogClose( &log );
© Copyright Mithral Communications & Design Inc.
1995-2024.
All rights reserved.
Mithral® and Cosm® are trademarks of
Mithral Communications & Design Inc.
|