Skip to content

Commit

Permalink
Added the option logfile to log message to text file. Removed level -…
Browse files Browse the repository at this point in the history
…1 to log to stderr, don't use always short
  • Loading branch information
AngelCarpintero authored and AngelCarpintero committed Mar 9, 2009
1 parent 42c63ef commit 0f71dab
Show file tree
Hide file tree
Showing 22 changed files with 405 additions and 351 deletions.
164 changes: 71 additions & 93 deletions conf.c

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
more parameters may be added later.
*/
struct config {
char *log_file;
int setup_mode;
int width;
int height;
Expand Down Expand Up @@ -79,7 +80,7 @@ struct config {
const char *tuner_device;
#endif
const char *video_device;
short unsigned int v4l2_palette;
int v4l2_palette;
const char *vidpipe;
const char *filepath;
const char *imagepath;
Expand Down Expand Up @@ -131,15 +132,15 @@ struct config {
* typedef for a param copy function.
*/
typedef struct context ** (* conf_copy_func)(struct context **, const char *, int);
typedef const char *(* conf_print_func)(struct context **, char **, int, unsigned short int);
typedef const char *(* conf_print_func)(struct context **, char **, int, unsigned int);

/**
* description for parameters in the config file
*/
typedef struct {
const char *param_name; /* name for this parameter */
const char *param_help; /* short explanation for parameter */
unsigned short int main_thread; /* belong only to main thread when value>0 */
unsigned int main_thread; /* belong only to main thread when value>0 */
int conf_value; /* pointer to a field in struct context */
conf_copy_func copy; /* a function to set the value in 'config' */
conf_print_func print; /* a function to output the value to a file */
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for motion trunk-r441.
# Generated by GNU Autoconf 2.61 for motion trunk-r442.
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Expand Down Expand Up @@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='motion'
PACKAGE_TARNAME='motion'
PACKAGE_VERSION='trunk-r441'
PACKAGE_STRING='motion trunk-r441'
PACKAGE_VERSION='trunk-r442'
PACKAGE_STRING='motion trunk-r442'
PACKAGE_BUGREPORT=''

ac_unique_file="motion.c"
Expand Down Expand Up @@ -1177,7 +1177,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures motion trunk-r441 to adapt to many kinds of systems.
\`configure' configures motion trunk-r442 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1238,7 +1238,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of motion trunk-r441:";;
short | recursive ) echo "Configuration of motion trunk-r442:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1376,7 +1376,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
motion configure trunk-r441
motion configure trunk-r442
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
Expand All @@ -1390,7 +1390,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by motion $as_me trunk-r441, which was
It was created by motion $as_me trunk-r442, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -8230,7 +8230,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by motion $as_me trunk-r441, which was
This file was extended by motion $as_me trunk-r442, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -8279,7 +8279,7 @@ Report bugs to <[email protected]>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
motion config.status trunk-r441
motion config.status trunk-r442
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Expand Down
7 changes: 2 additions & 5 deletions draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,17 +1076,14 @@ struct big_char big_table[sizeof(draw_table) / sizeof(struct draw_char)];

#define NEWLINE "\\n"

static int draw_textn (unsigned char *image, int startx, int starty, int width, const char *text, int len, unsigned short int factor)
static int draw_textn(unsigned char *image, unsigned int startx, unsigned int starty, unsigned int width, const char *text, int len, unsigned int factor)
{
int pos, x, y, line_offset, next_char_offs;
unsigned char *image_ptr, *char_ptr, **char_arr_ptr;

if (startx > width / 2)
startx -= len * (6 * (factor + 1));

if (startx < 0)
startx = 0;

if (startx + len * 6 * (factor + 1) >= width)
len = (width-startx-1)/(6*(factor+1));

Expand Down Expand Up @@ -1124,7 +1121,7 @@ static int draw_textn (unsigned char *image, int startx, int starty, int width,
return 0;
}

int draw_text (unsigned char *image, int startx, int starty, int width, const char *text, unsigned short int factor)
int draw_text(unsigned char *image, unsigned int startx, unsigned int starty, unsigned int width, const char *text, unsigned int factor)
{
int num_nl = 0;
const char *end, *begin;
Expand Down
4 changes: 2 additions & 2 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void exec_command(struct context *cnt, char *command, char *filename, int

exit(1);
} else if (debug_level >= CAMERA_VERBOSE) {
motion_log(-1, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp);
motion_log(0, 0, "%s: Executing external command '%s'", __FUNCTION__, stamp);
}
}

Expand All @@ -63,7 +63,7 @@ static void event_newfile(struct context *cnt ATTRIBUTE_UNUSED,
int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED,
char *filename, void *ftype, struct tm *tm ATTRIBUTE_UNUSED)
{
motion_log(-1, 0, "%s: File of type %ld saved to: %s", __FUNCTION__,
motion_log(0, 0, "%s: File of type %ld saved to: %s", __FUNCTION__,
(unsigned long)ftype, filename);
}

Expand Down
65 changes: 57 additions & 8 deletions logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@
#include "logger.h" /* already includes motion.h */
#include <stdarg.h>

static int log_mode = 1;
static FILE *logfile;

/**
* set_log_mode
*
* Set mode of logging , could be using syslog or files.
*/
void set_log_mode(int mode)
{
log_mode = mode;
}

/**
* set_logfile
*
* Set logfile to be used instead of syslog.
*/
FILE * set_logfile(const char *logfile_name)
{
return logfile = myfopen(logfile_name, "a");
}


/**
* str_time
*
* Return string with human readable time
*/
static char *str_time(void)
{
static char buffer[16];
time_t now = 0;

now = time(0);
strftime(buffer, 16, "%b %d %H:%M:%S", localtime(&now));
return buffer;
}

/**
* motion_log
*
Expand Down Expand Up @@ -56,8 +95,13 @@ void motion_log(int level, int errno_flag, const char *fmt, ...)
*/
errno_save = errno;

/* Prefix the message with the time and thread number */
if (!log_mode) {
n = snprintf(buf, sizeof(buf), "[%s] [%d] ", str_time(), threadnr);
} else {
/* Prefix the message with the thread number */
n = snprintf(buf, sizeof(buf), "[%d] ", threadnr);
n = snprintf(buf, sizeof(buf), "[%d] ", threadnr);
}

/* Next add the user's message */
va_start(ap, fmt);
Expand All @@ -78,15 +122,20 @@ void motion_log(int level, int errno_flag, const char *fmt, ...)
strncat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)), 1024 - strlen(buf));
#endif
}
/* If 'level' is not negative, send the message to the syslog */
if (level >= 0)
syslog(level, "%s", buf);

/* For printing to stderr we need to add a newline */
strncat(buf, "\n", 1024 - strlen(buf));
fputs(buf, stderr);
fflush(stderr);
if (!log_mode) {
strncat(buf, "\n", 1024 - strlen(buf));
fputs(buf, logfile);
fflush(logfile);

/* If log_mode, send the message to the syslog */
} else {
syslog(level, "%s", buf);
strncat(buf, "\n", 1024 - strlen(buf));
fputs(buf, stderr);
fflush(stderr);
}

/* Clean up the argument list routine */
va_end(ap);
}
Expand Down
2 changes: 2 additions & 0 deletions logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define CAMERA_VERBOSE 8 /* verbose level */
#define CAMERA_ALL 9 /* everything */

void set_log_mode(int mode);
FILE * set_logfile(const char *logfile_name);
void motion_log(int, int, const char *, ...);

#endif
4 changes: 4 additions & 0 deletions motion-dist.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ process_id_file /var/run/motion/motion.pid
# Start in Setup-Mode, daemon disabled. (default: off)
setup_mode off


# Use a file to save logs messages, if not defined stderr and syslog is used. (default: not defined)
;logfile

###########################################################
# Capture device options
############################################################
Expand Down
Loading

0 comments on commit 0f71dab

Please sign in to comment.