jcnelson / vdev

A device-file manager for *nix
GNU General Public License v3.0
101 stars 13 forks source link

logging to syslog #83

Closed suedi closed 8 years ago

suedi commented 8 years ago

Me and @obarun has been trying to log via syslog instead of logfile

It doesn't seem to work

with changing to logfile=syslog in vdevd.conf and restarting vdev I get logs in a file called syslog in the directory where I issue the command for example if in /root and issue command /etc/init.d/vdev restart I get log file /root/syslog

When I check that log with loglevel=debug it says at a lot of places
VDEV_LOGFILE=/root/syslog allthough in vdevd.conf I have logfile=syslog

seems like path is prepended somewhere and that makes check in vdevd/main.c fail line 74

if( strcmp( vdev.config->logfile_path, "syslog" ) == 0 ) {

         vdev_debug("%s", "Switching to syslog for messages\n");
         vdev_enable_syslog();
} 

I guess in my case here I compare "/root/syslog" with "syslog" and it fails

Do you know where the culprit is Jude?

jcnelson commented 8 years ago

@suedi @Obarun

I think this is fixed in d4f2645da3d19fa5c2082ad3a4cbcfb1bf3da44f. I re-worked the logging and subprocess routines to redirect a child process's stderr to a named pipe under /dev/metadata, and I added a thread to vdevd that gathers data written to this pipe and logs it with vdev_error. This should prevent subprocesses from mistakenly assuming that $VDEV_LOGFILE refers to an actual file (instead of the sentinel string "syslog", which vdevd interprets to write data to syslog instead of a file).

suedi commented 8 years ago

Hey man,

I will of course try to help you with that but could you please keep posts on vdev gitub on subject? that is: limited to problems with vdev.

I copied your question to a post on alphaOS forum, let us please continue there. see

http://alphaos.tuxfamily.org/forum/viewtopic.php?f=6&t=1354

Obarun commented 8 years ago

@jcnelson @suedi Really really sorry for this mistake, i haven't realize that i posted here. I though that i posted a private message to suedi. Sorry again to be dumber

suedi commented 8 years ago

I tried this again with the vdev as of commit 1f17250f5185de9bb24f5b2367f8fdf10c723f51

The behavior is still the same

suedi commented 8 years ago

Decided to look into this issue a bit and found config.c-->vdev_config_fullpaths()

Where some defined keys in config-file will get their value transformed to absolute path.

Also here is logfile_path defined as needed to be transformed. The need is there for normal log file but not for special case where logfile is "syslog".

So a change to something like

int vdev_config_fullpaths( struct vdev_config* conf ) {
  ...
  if( need_fullpath[i] != NULL && (*need_fullpath[i]) != NULL ) { //original line so to see where I entered my edit that starts below
      if( need_fullpath[i] == &conf->logfile_path && strncmp((*need_fullpath[i]), "syslog",7) == 0 ) {      
        continue;
      }
     ...
  }
  ...
}

Please feel free to educate me for better C-code.

With this setup I get very few mesages in syslog.

vdev_enable_syslog() is executed in main.c before the fork is happening so the child should retain the flag _VDEV_SYSLOG = 1

If i strace it I see more attempts of write. Is it only ERROR level that is getting written to syslog?

Could be so since I get warn and info messages in console, debug messages I cannot find however?

entries in syslog

Jan 14 21:06:01 [vdev] '/mnt/live/tmp/dev' is not on devtmpfs_
Jan 14 21:06:36 [vdev] REMOVE device: type 'unknown' at 'UNKNOWN' ('UNKNOWN' 0:0)_

strace of this run strace_syslog_issue83.txt

suedi commented 8 years ago

Looked a bit closer on this.

Seems like at least my system is setup to not log messages of level debug to syslog. logger -p debug "test of debug"wont work but logger -p info "test of info" does.

So normal not getting debug in syslog then.

The C logging works but bash log functions in vdevd/helpers/LINUX/subr.sh does not.

They log to stderr like

echo "[helpers] [ERROR]: $1" >&2

and that goes to console when set to log to syslog

I am not sure how you wish to solve that?

If you could use /dev/metadata/errpipe or the logger command to write to syslog

Could then be done like

echo "[helpers] [ERROR]: $1"  | logger -p error

Don't know if logger is available under dash though, I have dash->bash symlinked

https://unix.stackexchange.com/questions/164187/dash-equivalent-of-self-redirection-of-script-output seems to indicate it may be present?

suedi commented 8 years ago

Just remembered that I F***ed around a lot with code around the dup statements.

Pulled a new copy of the latest vdev.

Hacked in my solution in libvdev/config.c-->vdev_config_fullpaths() (repeated here for clarity)

int vdev_config_fullpaths( struct vdev_config* conf ) {
  ...
  if( need_fullpath[i] != NULL && (*need_fullpath[i]) != NULL ) { //original line so to see where I entered my edit that starts below
      if( need_fullpath[i] == &conf->logfile_path && strncmp((*need_fullpath[i]), "syslog",7) == 0 ) {      
        continue;
      }
     ...
  }
  ...
}

Now it works :+1:

Bash functions output also get served to syslog!

I think this wraps up this issue.

Awaiting your verdict Mr Nelson...

jcnelson commented 8 years ago

@suedi Your solution looks great! That's exactly what needed to happen. Thank you for all of your rigorous testing with using syslog :D

If you want to send me a pull request, I'll merge it ASAP.

suedi commented 8 years ago

pull request sent.

closing...