|
suricata
|
#include "threads.h"#include "conf.h"#include "util-buffer.h"#include "util-hash.h"#include "output-eve.h"

Go to the source code of this file.
Data Structures | |
| struct | ThreadLogFileHashEntry |
| struct | LogThreadedFileCtx_ |
| struct | LogFileTypeCtx_ |
| struct | LogFileCtx_ |
Macros | |
| #define | LOGFILE_RECONN_MIN_TIME 500 |
| #define | LOGFILE_ROTATE_INTERVAL 0x04 |
| #define | LOGFILE_EVE_BUFFER_SIZE 0 |
Typedefs | |
| typedef struct ThreadLogFileHashEntry | ThreadLogFileHashEntry |
| typedef struct LogThreadedFileCtx_ | LogThreadedFileCtx |
| typedef struct LogFileTypeCtx_ | LogFileTypeCtx |
| 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 } |
Functions | |
| LogFileCtx * | LogFileNewCtx (void) |
| LogFileNewCtx() Get a new LogFileCtx. | |
| int | LogFileFreeCtx (LogFileCtx *) |
| LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory) | |
| 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. | |
| int | SCConfLogOpenGeneric (SCConfNode *conf, LogFileCtx *, const char *, int) |
| open a generic output "log file", which may be a regular file or a socket | |
| int | SCConfLogReopen (LogFileCtx *) |
| Reopen a regular log file with the side-affect of truncating it. | |
| bool | SCLogOpenThreadedFile (const char *log_path, const char *append, LogFileCtx *parent_ctx) |
Definition in file util-logopenfile.h.
| #define LOGFILE_EVE_BUFFER_SIZE 0 |
Definition at line 175 of file util-logopenfile.h.
| #define LOGFILE_RECONN_MIN_TIME 500 |
Definition at line 169 of file util-logopenfile.h.
| #define LOGFILE_ROTATE_INTERVAL 0x04 |
Definition at line 172 of file util-logopenfile.h.
| typedef struct LogFileCtx_ LogFileCtx |
Global structure for Output Context
| typedef struct LogFileTypeCtx_ LogFileTypeCtx |
| typedef struct LogThreadedFileCtx_ LogThreadedFileCtx |
| typedef struct ThreadLogFileHashEntry ThreadLogFileHashEntry |
| enum 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.
| LogFileCtx * LogFileEnsureExists | ( | ThreadId | thread_id, |
| LogFileCtx * | parent_ctx | ||
| ) |
LogFileEnsureExists() Ensure a log file context for the thread exists.
| parent_ctx |
| LogFileCtx | * pointer if successful; NULL otherwise |
Definition at line 743 of file util-logopenfile.c.
References LogThreadedFileCtx_::append, ThreadLogFileHashEntry::ctx, LogFileCtx_::filename, HashTableRemove(), LogThreadedFileCtx_::ht, ThreadLogFileHashEntry::isopen, LogThreadedFileCtx_::mutex, SC_LOG_DEBUG, sc_log_global_log_level, SCGetThreadIdLong, SCLogDebug, SCMutexLock, SCMutexUnlock, ThreadLogFileHashEntry::slot_number, t_thread_name, LogFileCtx_::threaded, and LogFileCtx_::threads.
Referenced by CreateEveThreadCtx(), and JsonLogThreadInit().


| void LogFileFlush | ( | LogFileCtx * | file_ctx | ) |
Definition at line 971 of file util-logopenfile.c.
References LogFileCtx_::bytes_since_last_flush, LogFileCtx_::filename, LogFileCtx_::Flush, and SCLogDebug.
Referenced by OutputJsonFlush(), and OutputJsonLogFlush().

| int LogFileFreeCtx | ( | LogFileCtx * | lf_ctx | ) |
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
| lf_ctx | pointer to the OutputCtx |
| int | 1 if successful, 0 if error |
Definition at line 906 of file util-logopenfile.c.
References LogThreadedFileCtx_::append, BUG_ON, LogFileCtx_::Close, SCEveFileType_::Deinit, LogFileCtx_::filename, LogFileTypeCtx_::filetype, LogFileCtx_::filetype, LogFileCtx_::fp, LogFileCtx_::fp_mutex, HashTableFree(), LogThreadedFileCtx_::ht, LogFileTypeCtx_::init_data, LOGFILE_TYPE_FILETYPE, LOGFILE_TYPE_REDIS, LogThreadedFileCtx_::mutex, OutputUnregisterFileRotationFlag(), LogFileCtx_::parent, LogFileCtx_::prefix, LogFileCtx_::prefix_len, LogFileCtx_::rotation_flag, SCFree, SCMutexDestroy, SCReturnInt, LogFileCtx_::sensor_name, LogFileTypeCtx_::thread_data, SCEveFileType_::ThreadDeinit, LogFileCtx_::threaded, LogFileCtx_::threads, and LogFileCtx_::type.
Referenced by AlertFastLogInitCtx(), LogHttpLogInitCtx(), LogTcpDataLogInitCtx(), and OutputJsonInitCtx().


| LogFileCtx * LogFileNewCtx | ( | void | ) |
LogFileNewCtx() Get a new LogFileCtx.
| LogFileCtx | * pointer if successful, NULL if error |
Definition at line 692 of file util-logopenfile.c.
References LogFileCtx_::Close, LogFileCtx_::Flush, SCCalloc, and LogFileCtx_::Write.
Referenced by AlertFastLogInitCtx(), LogHttpLogInitCtx(), LogTcpDataLogInitCtx(), and OutputJsonInitCtx().

| int LogFileWrite | ( | LogFileCtx * | file_ctx, |
| MemBuffer * | buffer | ||
| ) |
Definition at line 977 of file util-logopenfile.c.
References LogFileTypeCtx_::filetype, LogFileCtx_::filetype, LogFileCtx_::fp_mutex, LogFileTypeCtx_::init_data, LOGFILE_TYPE_FILE, LOGFILE_TYPE_FILETYPE, LOGFILE_TYPE_REDIS, LOGFILE_TYPE_UNIX_DGRAM, LOGFILE_TYPE_UNIX_STREAM, MEMBUFFER_BUFFER, MEMBUFFER_OFFSET, MemBufferWriteString(), SCMutexLock, SCMutexUnlock, LogFileTypeCtx_::thread_data, LogFileCtx_::type, SCEveFileType_::Write, and LogFileCtx_::Write.
Referenced by OutputJSONBuffer(), and OutputJsonBuilderBuffer().


| 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
| conf | ConfNode structure for the output section in question |
| log_ctx | Log file context allocated by caller |
| default_filename | Default name of file to open, if not specified in ConfNode |
| rotate | Register the file for rotation in HUP. |
| 0 | on success |
| -1 | on error |
Definition at line 466 of file util-logopenfile.c.
References LogFileCtx_::buffer_size, DEFAULT_LOG_FILETYPE, DEFAULT_LOG_MODE_APPEND, FatalError, LogFileCtx_::filemode, LogFileCtx_::filename, LogFileCtx_::flags, LogFileCtx_::fp, LogFileCtx_::is_regular, LogFileCtx_::is_sock, IsRunModeOffline(), JSON_ESCAPE_SLASH, LogFileCtx_::json_flags, LOGFILE_EVE_BUFFER_SIZE, LOGFILE_ROTATE_INTERVAL, SCConfNode_::name, OutputRegisterFileRotationFlag(), ParseSizeStringU32(), PathIsAbsolute(), LogFileCtx_::rotate_interval, LogFileCtx_::rotate_time, LogFileCtx_::rotation_flag, SCConfigGetLogDirectory(), SCConfNodeLookupChild(), SCConfNodeLookupChildValue(), SCConfValIsFalse(), SCGetSecondsUntil(), SCLogConfig, SCLogDebug, SCLogError, SCLogInfo, SCLogOpenThreadedFile(), SCParseTimeSizeString(), SCRunmodeGet(), SCStrdup, LogFileCtx_::send_flags, LogFileCtx_::sock_type, StringParseUint32(), LogFileCtx_::threaded, and unlikely.
Referenced by AlertFastLogInitCtx(), LogHttpLogInitCtx(), and LogTcpDataLogInitCtx().


| 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 661 of file util-logopenfile.c.
References LogFileCtx_::buffer_size, LogFileCtx_::filemode, LogFileCtx_::filename, LogFileCtx_::fp, LogFileCtx_::is_regular, SCLogDebug, and SCLogWarning.
| bool SCLogOpenThreadedFile | ( | const char * | log_path, |
| const char * | append, | ||
| LogFileCtx * | parent_ctx | ||
| ) |
Definition at line 361 of file util-logopenfile.c.
References LogThreadedFileCtx_::append, DEFAULT_LOG_MODE_APPEND, FatalError, HashTableFree(), HashTableInit(), LogThreadedFileCtx_::ht, LogThreadedFileCtx_::mutex, SCCalloc, SCFree, SCLogError, SCMutexInit, SCStrdup, and LogFileCtx_::threads.
Referenced by SCConfLogOpenGeneric().

