Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
631784d9
Commit
631784d9
authored
Feb 09, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a way to replace the default logging mechanism
parent
8f929193
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
SDL_log.h
include/SDL_log.h
+16
-0
SDL_log.c
src/SDL_log.c
+38
-1
No files found.
include/SDL_log.h
View file @
631784d9
...
@@ -177,6 +177,22 @@ extern DECLSPEC void SDLCALL SDL_LogMessageV(int category,
...
@@ -177,6 +177,22 @@ extern DECLSPEC void SDLCALL SDL_LogMessageV(int category,
SDL_LogPriority
priority
,
SDL_LogPriority
priority
,
const
char
*
fmt
,
va_list
ap
);
const
char
*
fmt
,
va_list
ap
);
/**
* \brief The prototype for the log output function
*/
typedef
void
(
*
SDL_LogOutputFunction
)(
void
*
userdata
,
int
category
,
SDL_LogPriority
priority
,
const
char
*
message
);
/**
* \brief Get the current log output function.
*/
extern
DECLSPEC
void
SDLCALL
SDL_LogGetOutputFunction
(
SDL_LogOutputFunction
*
callback
,
void
**
userdata
);
/**
* \brief This function allows you to replace the default log output
* function with one of your own.
*/
extern
DECLSPEC
void
SDLCALL
SDL_LogSetOutputFunction
(
SDL_LogOutputFunction
callback
,
void
*
userdata
);
/* Ends C function definitions when using C++ */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
#ifdef __cplusplus
...
...
src/SDL_log.c
View file @
631784d9
...
@@ -45,11 +45,19 @@ typedef struct SDL_LogLevel
...
@@ -45,11 +45,19 @@ typedef struct SDL_LogLevel
struct
SDL_LogLevel
*
next
;
struct
SDL_LogLevel
*
next
;
}
SDL_LogLevel
;
}
SDL_LogLevel
;
/* The default log output function */
static
void
SDL_LogOutput
(
void
*
userdata
,
int
category
,
SDL_LogPriority
priority
,
const
char
*
message
);
static
SDL_LogLevel
*
SDL_loglevels
;
static
SDL_LogLevel
*
SDL_loglevels
;
static
SDL_LogPriority
SDL_application_priority
=
DEFAULT_APPLICATION_PRIORITY
;
static
SDL_LogPriority
SDL_application_priority
=
DEFAULT_APPLICATION_PRIORITY
;
static
SDL_LogPriority
SDL_default_priority
=
DEFAULT_PRIORITY
;
static
SDL_LogPriority
SDL_default_priority
=
DEFAULT_PRIORITY
;
static
SDL_LogOutputFunction
SDL_log_function
=
SDL_LogOutput
;
static
void
*
SDL_log_userdata
=
NULL
;
static
const
char
*
SDL_priority_prefixes
[
SDL_NUM_LOG_PRIORITIES
]
=
{
static
const
char
*
SDL_priority_prefixes
[
SDL_NUM_LOG_PRIORITIES
]
=
{
NULL
,
"VERBOSE"
,
"VERBOSE"
,
"DEBUG"
,
"DEBUG"
,
"INFO"
,
"INFO"
,
...
@@ -235,6 +243,11 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
...
@@ -235,6 +243,11 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
{
{
char
*
message
;
char
*
message
;
/* Nothing to do if we don't have an output function */
if
(
!
SDL_log_function
)
{
return
;
}
/* Make sure we don't exceed array bounds */
/* Make sure we don't exceed array bounds */
if
(
priority
<
0
||
priority
>=
SDL_NUM_LOG_PRIORITIES
)
{
if
(
priority
<
0
||
priority
>=
SDL_NUM_LOG_PRIORITIES
)
{
return
;
return
;
...
@@ -250,7 +263,14 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
...
@@ -250,7 +263,14 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
return
;
return
;
}
}
SDL_vsnprintf
(
message
,
SDL_MAX_LOG_MESSAGE
,
fmt
,
ap
);
SDL_vsnprintf
(
message
,
SDL_MAX_LOG_MESSAGE
,
fmt
,
ap
);
SDL_log_function
(
SDL_log_userdata
,
category
,
priority
,
message
);
SDL_stack_free
(
message
);
}
static
void
SDL_LogOutput
(
void
*
userdata
,
int
category
,
SDL_LogPriority
priority
,
const
char
*
message
)
{
#if defined(__WIN32__)
#if defined(__WIN32__)
/* Way too many allocations here, urgh */
/* Way too many allocations here, urgh */
{
{
...
@@ -277,7 +297,24 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
...
@@ -277,7 +297,24 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
#if HAVE_STDIO_H
#if HAVE_STDIO_H
fprintf
(
stderr
,
"%s: %s
\n
"
,
SDL_priority_prefixes
[
priority
],
message
);
fprintf
(
stderr
,
"%s: %s
\n
"
,
SDL_priority_prefixes
[
priority
],
message
);
#endif
#endif
SDL_stack_free
(
message
);
}
void
SDL_LogGetOutputFunction
(
SDL_LogOutputFunction
*
callback
,
void
**
userdata
)
{
if
(
callback
)
{
*
callback
=
SDL_log_function
;
}
if
(
userdata
)
{
*
userdata
=
SDL_log_userdata
;
}
}
void
SDL_LogSetOutputFunction
(
SDL_LogOutputFunction
callback
,
void
*
userdata
)
{
SDL_log_function
=
callback
;
SDL_log_userdata
=
userdata
;
}
}
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment