Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #22

Closed
drordahary opened this issue Jan 17, 2022 · 1 comment
Closed

Segmentation fault #22

drordahary opened this issue Jan 17, 2022 · 1 comment

Comments

@drordahary
Copy link

When initializing slog after I try to log once it fails with segmentation fault.
Here is the code below:

slog_init("logfile", 1, 0);
slog_config_t slg_cfg;
slg_cfg.eColorFormat = SLOG_COLORING_FULL;
slg_cfg.eDateControl = SLOG_TIME_ONLY;
strcpy(slg_cfg.sFileName, "logfile");
strcpy(slg_cfg.sFilePath, "../logs/");

slg_cfg.nTraceTid = 1;
slg_cfg.nToScreen = 0;
slg_cfg.nToFile = 1;
slg_cfg.nUseHeap = 0;
slg_cfg.nFlush = 0;
slg_cfg.nFlags = 1;
slog_config_set(&slg_cfg);

slog_trace("some.");

NOTE: I checked and the directory exists
I found out that what causes it to crash is this: slg_cfg.nFlags = 1;
If I remove that line it runs but doesn't output anything to the file

@kala13x
Copy link
Owner

kala13x commented Jan 27, 2022

Hi @drordahary,

This is not an issue. According to your copy, this is an expected result and I will tell you why.

slog_config_t structure has more fields than you are initializing in this example,
so some of the fields are not initialized while you are calling slog_config_set() function.

To fix this problem, you should call slog_config_get() function, which will initialize and fill
all the slog_config_t structure variables from the current configuration and then you can assign
only those parameters which you want to change and set the configuration with slog_config_set().

The correct example should look like:

slog_init("logfile", 1, 0);
slog_config_t slg_cfg;

//////////////////////////////////////////
// get the current configuration
slog_config_get(&slg_cfg);
//////////////////////////////////////////

// Change needed parameters
slg_cfg.eColorFormat = SLOG_COLORING_FULL;
slg_cfg.eDateControl = SLOG_TIME_ONLY;
strcpy(slg_cfg.sFileName, "logfile");
strcpy(slg_cfg.sFilePath, "../logs/");
slg_cfg.nTraceTid = 1;
slg_cfg.nToScreen = 0;
slg_cfg.nToFile = 1;
slg_cfg.nUseHeap = 0;
slg_cfg.nFlush = 0;
slg_cfg.nFlags = SLOG_FLAGS_ALL;

//////////////////////////////////////////
// Activate new configuration
slog_config_set(&slg_cfg);
//////////////////////////////////////////

slog_trace("some.");

Please also note that parameter 1 for nFlags is not a valid value,
You can use SLOG_FLAGS_ALL to enable all the logging flags,
or just elect only needed flags like:

slg_cfg.nFlags = SLOG_INFO | SLOG_ERROR | SLOG_WARN;

Regards,
Sandro

@kala13x kala13x closed this as completed Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants