Move LoggerModule to log.cpp.

This commit is contained in:
David Capello 2010-09-18 01:14:03 -03:00
parent f1e9814334
commit 9a9e40395f
6 changed files with 136 additions and 91 deletions

View File

@ -45,6 +45,7 @@ add_library(aseprite-library
gfxmode.cpp
job.cpp
launcher.cpp
log.cpp
recent_files.cpp
resource_finder.cpp
ui_context.cpp

View File

@ -46,6 +46,7 @@
#include "core/modules.h"
#include "file/file.h"
#include "intl/intl.h"
#include "log.h"
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"

View File

@ -18,27 +18,7 @@
#include "config.h"
#include <allegro/file.h>
#include <allegro/unicode.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include "jinete/jbase.h"
#include "core/core.h"
#include "resource_finder.h"
/* DOS and Windows needs "log" files (because their poor stderr support) */
#if defined ALLEGRO_DOS || defined ALLEGRO_WINDOWS
# define NEED_LOG
#endif
/* in DOS, print in stderr is like print in the video screen */
#if defined ALLEGRO_DOS
# define NO_STDERR
#endif
/**
* Current running mode of ASE.
@ -47,67 +27,6 @@
*/
int ase_mode = 0;
#ifdef NEED_LOG
/* log file info */
static std::string log_filename;
static FILE *log_fileptr = NULL;
#endif
LoggerModule::LoggerModule()
{
PRINTF("Logger module: starting\n");
#ifdef NEED_LOG
ResourceFinder rf;
rf.findInBinDir("aseprite.log");
log_filename = rf.first();
#endif
PRINTF("Logger module: started\n");
}
LoggerModule::~LoggerModule()
{
PRINTF("Logger module: shutting down (this is the last line)\n");
#ifdef NEED_LOG
if (log_fileptr) {
fclose(log_fileptr);
log_fileptr = NULL;
}
#endif
}
void verbose_printf(const char *format, ...)
{
if (!(ase_mode & MODE_VERBOSE))
return;
#ifdef NEED_LOG
if (!log_fileptr)
if (log_filename.size() > 0)
log_fileptr = fopen(log_filename.c_str(), "w");
if (log_fileptr)
#endif
{
va_list ap;
va_start(ap, format);
#ifndef NO_STDERR
vfprintf(stderr, format, ap);
fflush(stderr);
#endif
#ifdef NEED_LOG
vfprintf(log_fileptr, format, ap);
fflush(log_fileptr);
#endif
va_end(ap);
}
}
/**
* Returns true if the application is running in interactive mode (GUI).
*

View File

@ -19,8 +19,6 @@
#ifndef CORE_CORE_H_INCLUDED
#define CORE_CORE_H_INCLUDED
#include "jinete/jbase.h"
enum {
MODE_VERBOSE = 1, /* verbose mode status */
MODE_BATCH = 2, /* batch mode */
@ -29,14 +27,6 @@ enum {
extern int ase_mode;
class LoggerModule
{
public:
LoggerModule();
~LoggerModule();
};
void verbose_printf(const char *format, ...);
bool is_interactive();
#endif

103
src/log.cpp Normal file
View File

@ -0,0 +1,103 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro/file.h>
#include <allegro/unicode.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include "jinete/jbase.h"
#include "core/core.h"
#include "log.h"
#include "resource_finder.h"
/* DOS and Windows needs "log" files (because their poor stderr support) */
#if defined ALLEGRO_DOS || defined ALLEGRO_WINDOWS
# define NEED_LOG
#endif
/* in DOS, print in stderr is like print in the video screen */
#if defined ALLEGRO_DOS
# define NO_STDERR
#endif
#ifdef NEED_LOG
/* log file info */
static std::string log_filename;
static FILE *log_fileptr = NULL;
#endif
LoggerModule::LoggerModule()
{
PRINTF("Logger module: starting\n");
#ifdef NEED_LOG
ResourceFinder rf;
rf.findInBinDir("aseprite.log");
log_filename = rf.first();
#endif
PRINTF("Logger module: started\n");
}
LoggerModule::~LoggerModule()
{
PRINTF("Logger module: shutting down (this is the last line)\n");
#ifdef NEED_LOG
if (log_fileptr) {
fclose(log_fileptr);
log_fileptr = NULL;
}
#endif
}
void verbose_printf(const char *format, ...)
{
if (!(ase_mode & MODE_VERBOSE))
return;
#ifdef NEED_LOG
if (!log_fileptr)
if (log_filename.size() > 0)
log_fileptr = fopen(log_filename.c_str(), "w");
if (log_fileptr)
#endif
{
va_list ap;
va_start(ap, format);
#ifndef NO_STDERR
vfprintf(stderr, format, ap);
fflush(stderr);
#endif
#ifdef NEED_LOG
vfprintf(log_fileptr, format, ap);
fflush(log_fileptr);
#endif
va_end(ap);
}
}

31
src/log.h Normal file
View File

@ -0,0 +1,31 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LOG_H_INCLUDED
#define LOG_H_INCLUDED
class LoggerModule
{
public:
LoggerModule();
~LoggerModule();
};
void verbose_printf(const char* format, ...);
#endif