blob: 4d40cf26861ceaa66c3b55ea6993a76ff0f7805e [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 *
3 * log-client.c
4 *
5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 *
7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
9 *
10 * Created: Mon Mar 20 21:13:40 1995 ylo
11 *
12 * Client-side versions of debug(), log(), etc. These print to stderr.
13 * This is a stripped down version of log-server.c.
14 *
15 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "includes.h"
Damien Miller95def091999-11-25 00:26:21 +110018RCSID("$Id: log-client.c,v 1.3 1999/11/24 13:26:22 damien Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100019
20#include "xmalloc.h"
21#include "ssh.h"
22
Damien Miller5ce662a1999-11-11 17:57:39 +110023static LogLevel log_level = SYSLOG_LEVEL_INFO;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024
Damien Miller5ce662a1999-11-11 17:57:39 +110025/* Initialize the log.
Damien Miller95def091999-11-25 00:26:21 +110026 * av0 program name (should be argv[0])
27 * level logging level
28 */
Damien Miller5ce662a1999-11-11 17:57:39 +110029
30void
31log_init(char *av0, LogLevel level, SyslogFacility ignored1, int ignored2)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032{
Damien Miller95def091999-11-25 00:26:21 +110033 switch (level) {
34 case SYSLOG_LEVEL_QUIET:
35 case SYSLOG_LEVEL_ERROR:
36 case SYSLOG_LEVEL_FATAL:
37 case SYSLOG_LEVEL_INFO:
38 case SYSLOG_LEVEL_VERBOSE:
39 case SYSLOG_LEVEL_DEBUG:
40 log_level = level;
41 break;
42 default:
43 /* unchanged */
44 break;
45 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046}
47
Damien Miller5ce662a1999-11-11 17:57:39 +110048#define MSGBUFSIZE 1024
Damien Millerd4a8b7e1999-10-27 13:42:43 +100049
Damien Miller5ce662a1999-11-11 17:57:39 +110050void
51do_log(LogLevel level, const char *fmt, va_list args)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052{
Damien Miller95def091999-11-25 00:26:21 +110053 char msgbuf[MSGBUFSIZE];
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054
Damien Miller95def091999-11-25 00:26:21 +110055 if (level > log_level)
56 return;
57 if (level == SYSLOG_LEVEL_DEBUG)
58 fprintf(stderr, "debug: ");
59 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
60 fprintf(stderr, "%s", msgbuf);
61 fprintf(stderr, "\r\n");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062}