]> cygwin.com Git - cygwin-apps/setup.git/blame - log.cc
2002-02-24 Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
[cygwin-apps/setup.git] / log.cc
CommitLineData
89b1a15b
DD
1/*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@redhat.com>
13 *
14 */
15
16/* The purpose of this file is to centralize all the logging functions. */
17
b24c88b3
RC
18#if 0
19static const char *cvsid =
20 "\n%%% $Id$\n";
21#endif
89b1a15b
DD
22
23#include "win32.h"
24#include <stdio.h>
25#include <stdarg.h>
26#include <stdlib.h>
27#include <time.h>
28
29#include "resource.h"
30#include "msg.h"
31#include "log.h"
32#include "dialog.h"
33#include "state.h"
4a83b7b0 34#include "mkdir.h"
a351e48c 35#include "mount.h"
89b1a15b 36
3c054baf
RC
37#include "io_stream.h"
38
b24c88b3
RC
39struct LogEnt
40{
89b1a15b 41 LogEnt *next;
3c054baf 42 enum log_level level;
89b1a15b 43 time_t when;
3c054baf 44 String msg;
89b1a15b
DD
45};
46
47static LogEnt *first_logent = 0;
48static LogEnt **next_logent = &first_logent;
49
3c054baf
RC
50void
51log (enum log_level level, String const &message)
89b1a15b 52{
3c054baf 53 LogEnt *l = new LogEnt;
89b1a15b 54 l->next = 0;
3c054baf 55 l->level = level;
89b1a15b
DD
56 time (&(l->when));
57 *next_logent = l;
58 next_logent = &(l->next);
3c054baf 59 l->msg = message;
89b1a15b 60
3c054baf
RC
61 char b[100];
62 b[0]='\0';
63 if (level == LOG_TIMESTAMP)
89b1a15b
DD
64 {
65 struct tm *tm = localtime (&(l->when));
66 strftime (b, 1000, "%Y/%m/%d %H:%M:%S ", tm);
89b1a15b 67 }
3c054baf 68 l->msg = String (b) + message;
89b1a15b 69
3c054baf
RC
70 msg ("LOG: %d %s", l->level, l->msg.cstr_oneuse());
71}
72
73void
74log (enum log_level level, const char *fmt, ...)
75{
76 char buf[1000];
77 va_list args;
78 va_start (args, fmt);
79 vsprintf (buf, fmt, args);
80 log (level, String(buf));
89b1a15b
DD
81}
82
83void
3c054baf 84log_save (int babble, String const &filename, int append)
89b1a15b
DD
85{
86 static int been_here = 0;
87 if (been_here)
88 return;
89 been_here = 1;
90
3c054baf 91 io_stream::mkpath_p (PATH_TO_FILE, filename);
4a83b7b0 92
3c054baf 93 io_stream *f = io_stream::open(String("file://")+filename, append ? "at" : "wt");
89b1a15b
DD
94 if (!f)
95 {
3c054baf 96 fatal (NULL, IDS_NOLOGFILE, filename.cstr_oneuse());
89b1a15b
DD
97 return;
98 }
99
100 LogEnt *l;
101
b24c88b3 102 for (l = first_logent; l; l = l->next)
89b1a15b 103 {
3c054baf 104 if (babble || !(l->level == LOG_BABBLE))
89b1a15b 105 {
3c054baf
RC
106 char *tstr = l->msg.cstr();
107 f->write (tstr, strlen (tstr));
108 if (tstr[strlen (tstr) - 1] != '\n')
bb087dce 109 f->write ("\n", 1);
89b1a15b
DD
110 }
111 }
112
3c054baf 113 delete f;
89b1a15b
DD
114 been_here = 0;
115}
116
117void
118exit_setup (int exit_code)
119{
120 static int been_here = 0;
121 if (been_here)
122 ExitProcess (1);
123 been_here = 1;
124
125 if (exit_msg)
ab57ceaa 126 note (NULL, exit_msg);
89b1a15b
DD
127
128 log (LOG_TIMESTAMP, "Ending cygwin install");
129
3c054baf 130 if (source == IDC_SOURCE_DOWNLOAD || !get_root_dir ().size())
89b1a15b 131 {
3c054baf
RC
132 log_save (LOG_BABBLE, local_dir + "/setup.log.full", 0);
133 log_save (0, local_dir + "/setup.log", 1);
89b1a15b
DD
134 }
135 else
136 {
1ac649ed
RC
137 log_save (LOG_BABBLE, cygpath ("/var/log/setup.log.full"), 0);
138 log_save (0, cygpath ("/var/log/setup.log"), 1);
89b1a15b
DD
139 }
140
141 ExitProcess (exit_code);
142}
This page took 0.054461 seconds and 5 git commands to generate.