blob: 63cc79445a619839ee65227fd59feb0cdd9f5ba5 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
2
3log-client.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved
9
10Created: Mon Mar 20 21:13:40 1995 ylo
11
12Client-side versions of debug(), log(), etc. These print to stderr.
Damien Miller5ce662a1999-11-11 17:57:39 +110013This is a stripped down version of log-server.c.
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15*/
16
17#include "includes.h"
Damien Miller5ce662a1999-11-11 17:57:39 +110018RCSID("$Id: log-client.c,v 1.2 1999/11/11 06:57:39 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.
26 av0 program name (should be argv[0])
27 level logging level
28 */
29
30void
31log_init(char *av0, LogLevel level, SyslogFacility ignored1, int ignored2)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032{
Damien Miller5ce662a1999-11-11 17:57:39 +110033 switch (level)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100034 {
Damien Miller5ce662a1999-11-11 17:57:39 +110035 case SYSLOG_LEVEL_QUIET:
36 case SYSLOG_LEVEL_ERROR:
37 case SYSLOG_LEVEL_FATAL:
38 case SYSLOG_LEVEL_INFO:
39 case SYSLOG_LEVEL_CHAT:
40 case SYSLOG_LEVEL_DEBUG:
41 log_level = level;
42 break;
43 default:
44 /* unchanged */
45 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +100047}
48
Damien Miller5ce662a1999-11-11 17:57:39 +110049#define MSGBUFSIZE 1024
Damien Millerd4a8b7e1999-10-27 13:42:43 +100050
Damien Miller5ce662a1999-11-11 17:57:39 +110051void
52do_log(LogLevel level, const char *fmt, va_list args)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100053{
Damien Miller5ce662a1999-11-11 17:57:39 +110054 char msgbuf[MSGBUFSIZE];
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055
Damien Miller5ce662a1999-11-11 17:57:39 +110056 if (level > log_level)
57 return;
58 if (level == SYSLOG_LEVEL_DEBUG)
59 fprintf(stderr, "debug: ");
60 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
61 fprintf(stderr, "%s", msgbuf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062 fprintf(stderr, "\r\n");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100063}