Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 2 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * log-client.c |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 4 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 6 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 8 | * All rights reserved |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 9 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 10 | * Created: Mon Mar 20 21:13:40 1995 ylo |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 11 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 12 | * Client-side versions of debug(), log(), etc. These print to stderr. |
| 13 | * This is a stripped down version of log-server.c. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 14 | * |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 15 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 16 | |
| 17 | #include "includes.h" |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 18 | RCSID("$Id: log-client.c,v 1.6 2000/04/16 01:18:43 damien Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 19 | |
| 20 | #include "xmalloc.h" |
| 21 | #include "ssh.h" |
| 22 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 23 | static LogLevel log_level = SYSLOG_LEVEL_INFO; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 24 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 25 | /* Initialize the log. |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 26 | * av0 program name (should be argv[0]) |
| 27 | * level logging level |
| 28 | */ |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 29 | |
| 30 | void |
| 31 | log_init(char *av0, LogLevel level, SyslogFacility ignored1, int ignored2) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 32 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 33 | 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 46 | } |
| 47 | |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 48 | #define MSGBUFSIZ 1024 |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 49 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 50 | void |
| 51 | do_log(LogLevel level, const char *fmt, va_list args) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 52 | { |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 53 | char msgbuf[MSGBUFSIZ]; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 54 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 55 | 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 62 | } |