Const correctness in Log public interface

This commit is contained in:
BxmvVa4v
2022-09-01 13:20:38 +02:00
parent 33a05b17c1
commit 02efa9b1c7
5 changed files with 28 additions and 25 deletions

@ -946,7 +946,7 @@ bool File::closeLeastUsed () {
return true;
}
int64_t getFileSize ( char *filename ) {
int64_t getFileSize ( const char *filename ) {
#ifdef CYGWIN
return getFileSize_cygwin ( filename );

2
File.h

@ -36,7 +36,7 @@
bool doesFileExist ( char *filename ) ;
int64_t getFileSize ( char *filename ) ;
int64_t getFileSize ( const char *filename ) ;
int64_t getFileSize_cygwin ( char *filename ) ;

@ -1068,7 +1068,7 @@ void Images::thumbStart_r ( bool amThread ) {
//sprintf( cmd, scmd, ext, in, out);
char *wdir = g_hostdb.m_dir;
// can be /dev/stderr or like /var/gigablast/data/log000 etc.
char *logFile = g_log.getFilename();
const char *logFile = g_log.getFilename();
// wdir ends in / so this should work.
snprintf( cmd, 2500 ,
"LD_LIBRARY_PATH=%s %s%stopnm %s 2>> %s | "

18
Log.cpp

@ -89,7 +89,7 @@ bool renameCurrentLogFile ( ) {
}
bool Log::init ( char *filename ) {
bool Log::init ( const char *filename ) {
// set the main process id
//s_pid = getpidtid();
setPid();
@ -160,7 +160,7 @@ const char *getTypeString ( int32_t type ) {
*/
#define MAX_LINE_LEN 20048
bool Log::shouldLog ( int32_t type , char *msg ) {
bool Log::shouldLog ( int32_t type , const char *msg ) {
// always log warnings
if ( type == LOG_WARN ) return true;
if ( type == LOG_INFO ) return g_conf.m_logInfo;
@ -230,7 +230,7 @@ bool g_loggingEnabled = true;
// for testing:
//#define MAXLOGFILESIZE 3000
bool Log::logR ( int64_t now , int32_t type , char *msg , bool asterisk ,
bool Log::logR ( int64_t now , int32_t type , const char *msg , bool asterisk ,
bool forced ) {
// filter if we should
@ -305,7 +305,7 @@ bool Log::logR ( int64_t now , int32_t type , char *msg , bool asterisk ,
}
// msg resource
char *x = msg;
const char *x = msg;
//int32_t cc = 7;
// the first 7 bytes or up to the : must be ascii
//while ( p < pend && *x && is_alnum_a(*x) ) { *p++ = *x++; cc--; }
@ -445,7 +445,7 @@ static char s_problem = '\0';
// . 4 bytes = size of string space
// . X bytes = NULL terminated format string
// . X bytes = 0-3 bytes word-alignment padding
bool Log::logLater ( int64_t now, int32_t type, char *format, va_list ap ) {
bool Log::logLater ( int64_t now, int32_t type, const char *format, va_list ap ) {
//return false;
// we have to be in a sig handler
//if ( ! g_inSigHandler )
@ -473,7 +473,7 @@ bool Log::logLater ( int64_t now, int32_t type, char *format, va_list ap ) {
memcpy_ass ( s_ptr , format , flen );
s_ptr += flen;
// the type of each arg is given by format
char *p = format;
const char *p = format;
// point to the variable args data
char *pap = (char *)ap;
// loop looking for %s, %"INT32", etc.
@ -702,7 +702,7 @@ bool Log::dumpLog ( ) {
return true;
}
bool log ( int32_t type , char *formatString , ...) {
bool log ( int32_t type , const char *formatString , ...) {
if ( g_log.m_disabled ) return false;
// do not log it if we should not
if ( ! g_log.shouldLog ( type , formatString ) ) return false;
@ -729,7 +729,7 @@ bool log ( int32_t type , char *formatString , ...) {
return false;
}
bool log ( char *formatString , ... ) {
bool log ( const char *formatString , ... ) {
if ( g_log.m_disabled ) return false;
// do not log it if we should not
if ( ! g_log.shouldLog ( LOG_WARN , formatString ) ) return false;
@ -754,7 +754,7 @@ bool log ( char *formatString , ... ) {
return false;
}
bool logf ( int32_t type , char *formatString , ...) {
bool logf ( int32_t type , const char *formatString , ...) {
if ( g_log.m_disabled ) return false;
// do not log it if we should not
//if ( type == LOG_WARN && ! g_conf.m_logWarnings ) return false;

29
Log.h

@ -9,6 +9,9 @@
#ifndef _MYLOG_H_
#define _MYLOG_H_
#include <cstdarg>
#include <cstdint>
// THE TYPES OF LOG MESSAGES
// logs information pertaining to more complicated procedures, like
// the merging and dumping of data for the "db" component, or what urls are
@ -82,20 +85,20 @@ extern char *g_dbuf;
extern int32_t g_dbufSize;
#ifdef _CHECK_FORMAT_STRING_
bool log ( int32_t type , char *formatString , ... )
bool log ( int32_t type , const char *formatString , ... )
__attribute__ ((format(printf, 2, 3)));
bool log ( char *formatString , ... )
bool log ( const char *formatString , ... )
__attribute__ ((format(printf, 1, 2)));
bool logf ( int32_t type , char *formatString , ... )
bool logf ( int32_t type , const char *formatString , ... )
__attribute__ ((format(printf, 2, 3)));
#else
// may also syslog and fprintf the msg.
// ALWAYS returns FALSE (i.e. 0)!!!! so you can say return log.log(...)
bool log ( int32_t type , char *formatString , ... ) ;
bool log ( int32_t type , const char *formatString , ... ) ;
// this defaults to type of LOG_WARN
bool log ( char *formatString , ... ) ;
bool log ( const char *formatString , ... ) ;
// force it to be logged, even if off on log controls panel
bool logf ( int32_t type , char *formatString , ... ) ;
bool logf ( int32_t type , const char *formatString , ... ) ;
#endif
class Log {
@ -103,7 +106,7 @@ class Log {
public:
// returns true if opened log file successfully, otherwise false
bool init ( char *filename );
bool init ( const char *filename );
// . log this msg
// . "msg" must be NULL terminated
@ -112,11 +115,11 @@ class Log {
// . if "asterisk" is true we print an asterisk to indicate that
// the msg was actually logged earlier but only printed now because
// we were in a signal handler at the time
bool logR ( int64_t now, int32_t type, char *msg, bool asterisk ,
bool logR ( int64_t now, int32_t type, const char *msg, bool asterisk ,
bool forced = false );
// returns false if msg should not be logged, true if it should
bool shouldLog ( int32_t type , char *msg ) ;
bool shouldLog ( int32_t type , const char *msg ) ;
// just initialize with no file
Log () ;
@ -136,20 +139,20 @@ class Log {
void printBuf ( );
// this is only called when in a signal handler
bool logLater ( int64_t now , int32_t type , char *formatString ,
bool logLater ( int64_t now , int32_t type , const char *formatString ,
va_list ap );
bool m_disabled;
bool m_logTimestamps;
char *getFilename() { return m_filename; };
const char *getFilename() { return m_filename; };
private:
bool dumpLog ( ); // make room for the new ones
char *m_filename;
const char *m_filename;
int m_fd;
char *m_hostname;
int m_port;
@ -157,7 +160,7 @@ class Log {
int64_t m_logFileSize;
bool makeNewLogFile ( );
char *m_errorMsg [ MAX_LOG_MSGS ];
const char *m_errorMsg [ MAX_LOG_MSGS ];
int16_t m_errorMsgLen [ MAX_LOG_MSGS ];
int64_t m_errorTime [ MAX_LOG_MSGS ];
unsigned char m_errorType [ MAX_LOG_MSGS ];