2013-01-13 07:25:41 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xenia/logging.h>
|
|
|
|
|
|
|
|
#include <xenia/common.h>
|
|
|
|
|
|
|
|
|
2013-02-09 16:05:39 +00:00
|
|
|
void xe_log_line(const char* file_path, const uint32_t line_number,
|
|
|
|
const char* function_name, const char level_char,
|
|
|
|
const char* fmt, ...) {
|
2013-01-13 07:25:41 +00:00
|
|
|
const int kLogMax = 2048;
|
|
|
|
|
|
|
|
// Strip out just the filename from the path.
|
2013-02-09 16:05:39 +00:00
|
|
|
const char* filename = xestrrchra(file_path, XE_PATH_SEPARATOR);
|
2013-01-13 07:25:41 +00:00
|
|
|
if (filename) {
|
|
|
|
// Slash - skip over it.
|
|
|
|
filename++;
|
|
|
|
} else {
|
|
|
|
// No slash, entire thing is filename.
|
|
|
|
filename = file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scribble args into the print buffer.
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2013-02-09 16:05:39 +00:00
|
|
|
char buffer[kLogMax];
|
|
|
|
int buffer_length = xevsnprintfa(buffer, XECOUNT(buffer), fmt, args);
|
2013-01-13 07:25:41 +00:00
|
|
|
va_end(args);
|
|
|
|
if (buffer_length < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format string - add a trailing newline if required.
|
2013-02-09 16:05:39 +00:00
|
|
|
const char* outfmt;
|
2013-01-13 07:25:41 +00:00
|
|
|
if ((buffer_length >= 1) && buffer[buffer_length - 1] == '\n') {
|
2013-02-09 16:05:39 +00:00
|
|
|
outfmt = "XE[%c] %s:%d: %s";
|
2013-01-13 07:25:41 +00:00
|
|
|
} else {
|
2013-02-09 16:05:39 +00:00
|
|
|
outfmt = "XE[%c] %s:%d: %s\n";
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 04:11:27 +00:00
|
|
|
#if 0// defined(OutputDebugString)
|
2013-02-09 16:05:39 +00:00
|
|
|
char full_output[kLogMax];
|
|
|
|
if (xesnprintfa(full_output, XECOUNT(buffer), outfmt, level_char,
|
|
|
|
filename, line_number, buffer) >= 0) {
|
|
|
|
OutputDebugStringA(full_output);
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
XEIGNORE(fprintf(stdout, outfmt, level_char, filename, line_number, buffer));
|
2013-05-23 07:26:55 +00:00
|
|
|
fflush(stdout);
|
2013-01-13 07:25:41 +00:00
|
|
|
#endif // OutputDebugString
|
|
|
|
}
|