PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/l.c

http://bdremote-ng.googlecode.com/
C | 77 lines | 30 code | 14 blank | 33 comment | 5 complexity | 7c5dda462f7880bbfb3c48a4ac2f17d2 MD5 | raw file
 1/*
 2 *  bdremoteng - helper daemon for Sony(R) BD Remote Control
 3 *  Based on bdremoted, written by Anton Starikov <antst@mail.ru>.
 4 *
 5 *  Copyright (C) 2009  Michael Wojciechowski <wojci@wojci.dk>
 6 *
 7 *
 8 *  This program is free software; you can redistribute it and/or modify
 9 *  it under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation; either version 2 of the License, or
11 *  (at your option) any later version.
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *  GNU General Public License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with this program; if not, write to the Free Software
20 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 */
23
24/** \ingroup log */
25/*@{*/
26
27/*! \file l.c
28  \brief Logging implementation.
29
30  Support function to setup logging to a file/stdout.
31
32*/
33
34#include "l.h"
35
36#include <stdio.h>
37
38#include <globaldefs.h>
39
40/** Use this file for logging to using fprintf - the macros in
41    globaldefs.h use it.*/
42FILE* printStream = NULL;
43
44void setDefaultLog()
45{
46   printStream = stdout;
47}
48
49int setLogFile(const configuration* _config)
50{
51   if (_config->log_filename_set)
52      {
53         FILE* f = fopen(_config->log_filename, "a");
54
55         if (f == NULL)
56            {
57               printf("Unable to open log file '%s'.\n", _config->log_filename);
58               return BDREMOTE_FAIL;
59            }
60
61         printStream = f;
62      }
63
64   return BDREMOTE_OK;
65}
66
67void closeLogFile()
68{
69   if (printStream != stdout)
70      {
71         fclose(printStream);
72         printStream = stdout;
73      }
74}
75
76/*@}*/
77