Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
| 2 | |
| 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. |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 13 | This is a stripped down version of log-server.c. |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 14 | |
| 15 | */ |
| 16 | |
| 17 | #include "includes.h" |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 18 | RCSID("$Id: log-client.c,v 1.2 1999/11/11 06:57:39 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. |
| 26 | av0 program name (should be argv[0]) |
| 27 | level logging level |
| 28 | */ |
| 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 | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 33 | switch (level) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 34 | { |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 35 | 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 46 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 47 | } |
| 48 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 49 | #define MSGBUFSIZE 1024 |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 50 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 51 | void |
| 52 | do_log(LogLevel level, const char *fmt, va_list args) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 53 | { |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 54 | char msgbuf[MSGBUFSIZE]; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 55 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 56 | 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 62 | fprintf(stderr, "\r\n"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 63 | } |