* Add support for user-configurable log level settings.

This commit is contained in:
Justin Maggard 2012-02-14 18:25:39 +00:00
parent 774d8f9f6e
commit ba7e33a062
8 changed files with 53 additions and 16 deletions

7
log.c
View File

@ -62,11 +62,11 @@ log_init(const char *fname, const char *debug)
if (debug)
{
char *rhs, *lhs, *p;
const char *rhs, *lhs, *nlhs, *p;
int n;
int level, facility;
memset(&log_level_set, 0, sizeof(log_level_set));
rhs = lhs = (char*) debug;
rhs = nlhs = debug;
while (rhs && (rhs = strchr(rhs, '='))) {
rhs++;
p = strchr(rhs, ',');
@ -75,7 +75,8 @@ log_init(const char *fname, const char *debug)
if (!(strncasecmp(level_name[level], rhs, n)))
break;
}
rhs = p;
lhs = nlhs;
rhs = nlhs = p;
if (!(level_name[level])) {
// unknown level
continue;

View File

@ -350,6 +350,7 @@ init(int argc, char * * argv)
char buf[PATH_MAX];
char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'};
char log_str[72] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
char *log_level = NULL;
/* first check if "-f" option is used */
for(i=2; i<argc; i++)
@ -541,6 +542,9 @@ init(int argc, char * * argv)
}
strncpyt(log_path, path, PATH_MAX);
break;
case UPNPLOGLEVEL:
log_level = ary_options[i].value;
break;
case UPNPINOTIFY:
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
CLEARFLAG(INOTIFY_MASK);
@ -777,22 +781,29 @@ init(int argc, char * * argv)
}
if( verbose_flag )
{
strcpy(log_str+65, "debug");
log_level = log_str;
}
else if( !log_level )
{
log_level = log_str;
}
if(debug_flag)
{
pid = getpid();
log_init(NULL, log_str);
log_init(NULL, log_level);
}
else
{
pid = daemonize();
#ifdef READYNAS
log_init("/var/log/upnp-av.log", log_str);
log_init("/var/log/upnp-av.log", log_level);
#else
if( access(db_path, F_OK) != 0 )
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
sprintf(buf, "%s/minidlna.log", log_path);
log_init(buf, log_str);
log_init(buf, log_level);
#endif
}

View File

@ -22,6 +22,10 @@ media_dir=/opt
# set this if you would like to specify the directory where you want MiniDLNA to store its log file
#log_dir=/var/log
# set this to change the verbosity of the information that is logged
# each section can use a different level: off, fatal, error, warn, info, or debug
#log_level=general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn
# this should be a list of file names to check for when searching for album art
# note: names should be delimited with a forward slash ("/")
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

View File

@ -516,8 +516,6 @@ close:
* process SSDP M-SEARCH requests and responds to them */
void
ProcessSSDPRequest(int s, unsigned short port)
/*ProcessSSDPRequest(int s, struct lan_addr_s * lan_addr, int n_lan_addr,
unsigned short port)*/
{
int n;
char bufr[1500];
@ -547,10 +545,8 @@ ProcessSSDPRequest(int s, unsigned short port)
if( bufr[i] == '*' )
break;
}
if( !strcasestr(bufr+i, "HTTP/1.1") )
{
if( !strcasestrc(bufr+i, "HTTP/1.1", '\r') )
return;
}
while(i < n)
{
while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n'))
@ -601,7 +597,6 @@ ProcessSSDPRequest(int s, unsigned short port)
}
ParseUPnPClient(loc);
}
return;
}
else if(memcmp(bufr, "M-SEARCH", 8) == 0)
{
@ -612,10 +607,8 @@ ProcessSSDPRequest(int s, unsigned short port)
if( bufr[i] == '*' )
break;
}
if( !strcasestr(bufr+i, "HTTP/1.1") )
{
if( !strcasestrc(bufr+i, "HTTP/1.1", '\r') )
return;
}
while(i < n)
{
while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n'))

View File

@ -57,6 +57,7 @@ static const struct {
{ UPNPINOTIFY, "inotify" },
{ UPNPDBDIR, "db_dir" },
{ UPNPLOGDIR, "log_dir" },
{ UPNPLOGLEVEL, "log_level" },
{ UPNPMINISSDPDSOCKET, "minissdpdsocket"},
{ ENABLE_TIVO, "enable_tivo" },
{ ENABLE_DLNA_STRICT, "strict_dlna" },

View File

@ -51,6 +51,7 @@ enum upnpconfigoptions {
UPNPINOTIFY, /* enable inotify on the media directories */
UPNPDBDIR, /* base directory to store the database and album art cache */
UPNPLOGDIR, /* base directory to store the log file */
UPNPLOGLEVEL, /* logging verbosity */
UPNPMINISSDPDSOCKET, /* minissdpdsocket */
ENABLE_TIVO, /* enable support for streaming images and music to TiVo */
ENABLE_DLNA_STRICT, /* strictly adhere to DLNA specs */

25
utils.c
View File

@ -106,7 +106,7 @@ strstrc(const char *s, const char *p, const char t)
endptr = strchr(s, t);
if (!endptr)
return NULL;
return strstr(s, p);
plen = strlen(p);
slen = endptr - s;
@ -121,6 +121,29 @@ strstrc(const char *s, const char *p, const char t)
return NULL;
}
char *
strcasestrc(const char *s, const char *p, const char t)
{
char *endptr;
size_t slen, plen;
endptr = strchr(s, t);
if (!endptr)
return strcasestr(s, p);
plen = strlen(p);
slen = endptr - s;
while (slen >= plen)
{
if (*s == *p && strncasecmp(s+1, p+1, plen-1) == 0)
return (char*)s;
s++;
slen--;
}
return NULL;
}
char *
modifyString(char * string, const char * before, const char * after, short like)
{

View File

@ -39,6 +39,9 @@ trim(char *str);
char *
strstrc(const char *s, const char *p, const char t);
char *
strcasestrc(const char *s, const char *p, const char t);
char *
modifyString(char * string, const char * before, const char * after, short like);