2 * SiS 7018, Trident 4D Wave DX/NX, Acer Lab M5451 Sound Driver.
3 * Copyright (c) 2002, 2008-2011 S.Zharski <imker@gmx.li>
4 * Distributed under the terms of the MIT license.
17 bool gTraceOn
= false;
18 bool gTruncateLogFile
= false;
19 bool gAddTimeStamp
= true;
20 static char *gLogFilePath
= NULL
;
27 if (gLogFilePath
== NULL
)
30 int flags
= O_WRONLY
| O_CREAT
| ((gTruncateLogFile
) ? O_TRUNC
: 0);
31 int fd
= open(gLogFilePath
, flags
, 0666);
35 mutex_init(&gLogLock
, DRIVER_NAME
"-logging");
41 void *handle
= load_driver_settings(DRIVER_NAME
);
45 gTraceOn
= get_driver_boolean_parameter(handle
, "trace", gTraceOn
, true);
46 gTruncateLogFile
= get_driver_boolean_parameter(handle
, "truncate_logfile",
47 gTruncateLogFile
, true);
48 gAddTimeStamp
= get_driver_boolean_parameter(handle
, "add_timestamp",
50 const char * logFilePath
= get_driver_parameter(handle
, "logfile",
51 NULL
, "/var/log/"DRIVER_NAME
".log");
52 if (logFilePath
!= NULL
) {
53 gLogFilePath
= strdup(logFilePath
);
56 unload_driver_settings(handle
);
62 void release_settings()
64 if (gLogFilePath
!= NULL
) {
65 mutex_destroy(&gLogLock
);
71 void SiS7018_trace(bool force
, const char* func
, const char *fmt
, ...)
73 if (!(force
|| gTraceOn
)) {
78 static const char *prefix
= DRIVER_NAME
":";
79 static char buffer
[1024];
80 char *buf_ptr
= buffer
;
81 if (gLogFilePath
== NULL
) {
82 strlcpy(buffer
, prefix
, sizeof(buffer
));
83 buf_ptr
+= strlen(prefix
);
87 bigtime_t time
= system_time();
88 uint32 msec
= time
/ 1000;
89 uint32 sec
= msec
/ 1000;
90 sprintf(buf_ptr
, "%02ld.%02ld.%03ld:",
91 sec
/ 60, sec
% 60, msec
% 1000);
92 buf_ptr
+= strlen(buf_ptr
);
96 sprintf(buf_ptr
, "%s::", func
);
97 buf_ptr
+= strlen(buf_ptr
);
100 va_start(arg_list
, fmt
);
101 vsprintf(buf_ptr
, fmt
, arg_list
);
104 if (gLogFilePath
== NULL
) {
109 mutex_lock(&gLogLock
);
110 int fd
= open(gLogFilePath
, O_WRONLY
| O_APPEND
);
112 write(fd
, buffer
, strlen(buffer
));
115 mutex_unlock(&gLogLock
);