suricata
util-logopenfile.h File Reference
#include "threads.h"
#include "conf.h"
#include "util-buffer.h"
#include "util-hash.h"
#include "output-eve.h"
Include dependency graph for util-logopenfile.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ThreadLogFileHashEntry
 
struct  LogThreadedFileCtx_
 
struct  LogFileTypeCtx_
 
struct  LogFileEntry_
 
struct  LogFileCtx_
 

Macros

#define LOGFILE_RECONN_MIN_TIME   500
 
#define LOGFILE_EVE_BUFFER_SIZE   0
 

Typedefs

typedef struct ThreadLogFileHashEntry ThreadLogFileHashEntry
 
typedef struct LogThreadedFileCtx_ LogThreadedFileCtx
 
typedef struct LogFileTypeCtx_ LogFileTypeCtx
 
typedef struct LogFileEntry_ LogFileEntry
 
typedef enum LogFileRotateUnit_ LogFileRotateUnit
 
typedef struct LogFileCtx_ LogFileCtx
 

Enumerations

enum  LogFileType {
  LOGFILE_TYPE_FILE, LOGFILE_TYPE_UNIX_DGRAM, LOGFILE_TYPE_UNIX_STREAM, LOGFILE_TYPE_REDIS,
  LOGFILE_TYPE_FILETYPE, LOGFILE_TYPE_NOTSET
}
 
enum  LogFileRotateUnit_ {
  LOGFILE_ROTATE_NONE = 0, LOGFILE_ROTATE_ON_FIXED_PERIOD, LOGFILE_ROTATE_ON_NEW_MINUTE, LOGFILE_ROTATE_ON_NEW_HOUR,
  LOGFILE_ROTATE_ON_NEW_DAY
}
 

Functions

LogFileCtx * LogFileNewCtx (void)
 LogFileNewCtx() Get a new LogFileCtx. More...
 
int LogFileFreeCtx (LogFileCtx *)
 LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory) More...
 
int LogFileWrite (LogFileCtx *file_ctx, MemBuffer *buffer)
 
void LogFileFlush (LogFileCtx *file_ctx)
 
LogFileCtx * LogFileEnsureExists (ThreadId thread_id, LogFileCtx *lf_ctx)
 LogFileEnsureExists() Ensure a log file context for the thread exists. More...
 
int SCConfLogOpenGeneric (SCConfNode *conf, LogFileCtx *, const char *, int)
 open a generic output "log file", which may be a regular file or a socket More...
 
int SCConfLogReopen (LogFileCtx *)
 Reopen a regular log file with the side-affect of truncating it. More...
 
bool SCLogOpenThreadedFile (const char *log_path, const char *append, LogFileCtx *parent_ctx)
 
void LogFileRegister (LogFileCtx *ctx)
 Register a LogFileCtx for maintenance operations. More...
 
void LogFileUnregister (LogFileCtx *ctx)
 Unregister a LogFileCtx from maintenance operations. More...
 
void LogFileFlushAll (void)
 Flush all registered LogFileCtx instances. More...
 
void LogFileRotateAll (void)
 Check rotation for all registered LogFileCtx instances. More...
 
void LogFileRegisterTests (void)
 

Detailed Description

Macro Definition Documentation

◆ LOGFILE_EVE_BUFFER_SIZE

#define LOGFILE_EVE_BUFFER_SIZE   0

Definition at line 195 of file util-logopenfile.h.

◆ LOGFILE_RECONN_MIN_TIME

#define LOGFILE_RECONN_MIN_TIME   500

Definition at line 192 of file util-logopenfile.h.

Typedef Documentation

◆ LogFileCtx

typedef struct LogFileCtx_ LogFileCtx

Global structure for Output Context

◆ LogFileEntry

typedef struct LogFileEntry_ LogFileEntry

◆ LogFileRotateUnit

◆ LogFileTypeCtx

◆ LogThreadedFileCtx

◆ ThreadLogFileHashEntry

Enumeration Type Documentation

◆ LogFileRotateUnit_

Enumerator
LOGFILE_ROTATE_NONE 
LOGFILE_ROTATE_ON_FIXED_PERIOD 
LOGFILE_ROTATE_ON_NEW_MINUTE 
LOGFILE_ROTATE_ON_NEW_HOUR 
LOGFILE_ROTATE_ON_NEW_DAY 

Definition at line 76 of file util-logopenfile.h.

◆ LogFileType

Enumerator
LOGFILE_TYPE_FILE 
LOGFILE_TYPE_UNIX_DGRAM 
LOGFILE_TYPE_UNIX_STREAM 
LOGFILE_TYPE_REDIS 
LOGFILE_TYPE_FILETYPE 

New style or modular filetypes.

LOGFILE_TYPE_NOTSET 

Definition at line 38 of file util-logopenfile.h.

Function Documentation

◆ LogFileEnsureExists()

LogFileCtx* LogFileEnsureExists ( ThreadId  thread_id,
LogFileCtx *  parent_ctx 
)

LogFileEnsureExists() Ensure a log file context for the thread exists.

Parameters
parent_ctx
Return values
LogFileCtx* pointer if successful; NULL otherwise

Definition at line 847 of file util-logopenfile.c.

References LogThreadedFileCtx_::mutex, SCMutexLock, LogFileCtx_::threaded, and LogFileCtx_::threads.

Referenced by CreateEveThreadCtx(), and JsonLogThreadInit().

Here is the caller graph for this function:

◆ LogFileFlush()

void LogFileFlush ( LogFileCtx *  file_ctx)

◆ LogFileFlushAll()

void LogFileFlushAll ( void  )

Flush all registered LogFileCtx instances.

Called by the maintenance thread to flush all active file-based loggers.

Definition at line 1148 of file util-logopenfile.c.

References SCMutexLock.

◆ LogFileFreeCtx()

◆ LogFileNewCtx()

LogFileCtx* LogFileNewCtx ( void  )

LogFileNewCtx() Get a new LogFileCtx.

Return values
LogFileCtx* pointer if successful, NULL if error

Definition at line 795 of file util-logopenfile.c.

References SCCalloc, and LogFileCtx_::Write.

Referenced by AlertFastLogInitCtx(), LogTcpDataLogInitCtx(), and OutputJsonInitCtx().

Here is the caller graph for this function:

◆ LogFileRegister()

void LogFileRegister ( LogFileCtx *  ctx)

Register a LogFileCtx for maintenance operations.

Adds a LogFileCtx to the global log file list so the heartbeat thread can perform flush and rotation on it.

Parameters
ctxThe LogFileCtx to register (must be LOGFILE_TYPE_FILE)

Definition at line 1099 of file util-logopenfile.c.

References LogFileEntry_::ctx, ctx, LOGFILE_TYPE_FILE, SCLogError, SCMalloc, and SCMutexLock.

◆ LogFileRegisterTests()

void LogFileRegisterTests ( void  )

Definition at line 1328 of file util-logopenfile.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ LogFileRotateAll()

void LogFileRotateAll ( void  )

Check rotation for all registered LogFileCtx instances.

Called by the maintenance thread to trigger rotation checks on all registered log contexts during zero-traffic periods.

Definition at line 1166 of file util-logopenfile.c.

References SCMutexLock.

◆ LogFileUnregister()

void LogFileUnregister ( LogFileCtx *  ctx)

Unregister a LogFileCtx from maintenance operations.

Removes a LogFileCtx from the global log file list.

Parameters
ctxThe LogFileCtx to unregister

Definition at line 1125 of file util-logopenfile.c.

References ctx, and SCMutexLock.

Referenced by LogFileFreeCtx().

Here is the caller graph for this function:

◆ LogFileWrite()

◆ SCConfLogOpenGeneric()

int SCConfLogOpenGeneric ( SCConfNode *  conf,
LogFileCtx *  log_ctx,
const char *  default_filename,
int  rotate 
)

open a generic output "log file", which may be a regular file or a socket

Parameters
confConfNode structure for the output section in question
log_ctxLog file context allocated by caller
default_filenameDefault name of file to open, if not specified in ConfNode
rotateRegister the file for rotation in HUP.
Return values
0on success
-1on error

Definition at line 564 of file util-logopenfile.c.

References LogFileCtx_::compress_ipv6, FatalError, LogFileCtx_::fp, LOGFILE_ROTATE_ON_FIXED_PERIOD, LOGFILE_ROTATE_ON_NEW_DAY, LOGFILE_ROTATE_ON_NEW_HOUR, LOGFILE_ROTATE_ON_NEW_MINUTE, PathIsAbsolute(), LogFileCtx_::rotate_interval, LogFileCtx_::rotate_unit, SCConfigGetLogDirectory(), SCConfNodeLookupChildValue(), SCConfValIsTrue(), SCLogError, and SCParseTimeSizeString().

Referenced by AlertFastLogInitCtx(), and LogTcpDataLogInitCtx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCConfLogReopen()

int SCConfLogReopen ( LogFileCtx *  log_ctx)

Reopen a regular log file with the side-affect of truncating it.

This is useful to clear the log file and start a new one, or to re-open the file after its been moved by something external (eg. logrotate).

Definition at line 764 of file util-logopenfile.c.

References LogFileCtx_::filename, LogFileCtx_::fp, LogFileCtx_::is_regular, SCLogDebug, and SCLogWarning.

◆ SCLogOpenThreadedFile()

bool SCLogOpenThreadedFile ( const char *  log_path,
const char *  append,
LogFileCtx *  parent_ctx 
)

Definition at line 462 of file util-logopenfile.c.

References HashTableInit(), LogThreadedFileCtx_::ht, SCCalloc, SCLogError, and LogFileCtx_::threads.

Here is the call graph for this function: