 58b20109cf
			
		
	
	58b20109cf
	
	
	
		
			
			import sys
import yaml
with open(sys.argv[1]) as fp:
    data = fp.read()
if not data.find("---") == 0:
    # no head
    print("NO YAML HEAD FOUND")
    sys.exit(-1)
data = data[3:]
head_end = data.find("---")
head = data[0:head_end]
data = data[head_end+3:]
metadata = yaml.safe_load(head)
cats = metadata.pop('categories', None)
if cats != None:
    if type(cats) == list:
        tags = cats
    elif type(cats) == str:
        tags = cats.split()
    tags = list(map(lambda t: t.lower(), tags))
    metadata["tags"] = ", ".join(tags)
    new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}"
    # write it
    print(f"coverted: categories to tags: {tags} - {sys.argv[1]}")
    with open(sys.argv[1], "w") as fp:
        fp.write(new_data)
    sys.exit(0)
if not metadata.get("tags", None):
    metadata["tags"] = "untagged"
    new_data = f"---\n{yaml.dump(metadata, default_flow_style=False)}---{data}"
    print(f"untagged: {sys.argv[1]}")
    # write it
    with open(sys.argv[1], "w") as fp:
        fp.write(new_data)
    sys.exit(0)
print("No changes needed")
		
	
		
			
				
	
	
	
		
			1.6 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.6 KiB
		
	
	
	
	
	
	
	
comments, date, layout, tags, title
| comments | date | layout | tags | title | 
|---|---|---|---|---|
| true | 2015-02-21 00:41 | post | mac, osx, syslog, cheatsheet | Syslog on Mac OS X: Cheat Sheet | 
This is a quick cheatsheet to work with syslog(1) implementation OS X uses.
Console.app provides a nice UI to access logs in mac, you can do some basic filtering and search, but its limited in terms of raw control a terminal gives you.
/usr/bin/syslog can be used to both send and receive logs. Alternatively logger(1) can be used to send logs to syslog.
Print logs from a specific facilitiy
# -w: similar to tailf
syslog -k Facility local1 -w
Sending logs
# -l severity level
syslog -s "message"
Sending logs upstream to another syslog server
Syslog can forward your logs too. The configuration resides in /etc/syslog.conf. You can append forwarding rules in this file, format is
# Tab separated
Facility.Level    @IPADDR:PORT
After this reload syslog daemon.
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plistp
Extra reading
- asl.conf(5)- Configuration file for Apple Syslog Log (A syslog superset apple implements), this is where all the logic to route logs are set facility.level