blob: e86a2e3309568bb398ab6e27ebfc00889a15f5f7 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller4af51302000-04-16 11:18:38 +10002 *
Damien Miller95def091999-11-25 00:26:21 +11003 * log-client.c
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Miller95def091999-11-25 00:26:21 +11005 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Miller95def091999-11-25 00:26:21 +11007 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10009 *
Damien Miller95def091999-11-25 00:26:21 +110010 * Created: Mon Mar 20 21:13:40 1995 ylo
Damien Miller4af51302000-04-16 11:18:38 +100011 *
Damien Miller95def091999-11-25 00:26:21 +110012 * Client-side versions of debug(), log(), etc. These print to stderr.
13 * This is a stripped down version of log-server.c.
Damien Miller4af51302000-04-16 11:18:38 +100014 *
Damien Miller95def091999-11-25 00:26:21 +110015 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016
17#include "includes.h"
Damien Miller4af51302000-04-16 11:18:38 +100018RCSID("$Id: log-client.c,v 1.6 2000/04/16 01:18:43 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 Miller98c7ad62000-03-09 21:27:49 +110048#define MSGBUFSIZ 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 Miller98c7ad62000-03-09 21:27:49 +110053 char msgbuf[MSGBUFSIZ];
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}